HTML Daten mit JavaScript auslesen

Standard-Daten auslesen

HTML

	<div id="zahl">2</div>

JS

	zahl = document.getElementById('zahl');
	zahl = parseInt(zahl.innerHTML);

HTML

	<div id="zahl">2.56</div>

JS

	zahl = document.getElementById('zahl');
	zahl = parseFloat(zahl.innerHTML);

HTML

	<div id="string">Text</div>

JS

	zahl = document.getElementById('string');
	zahl = String(zahl.innerHTML);

Standard-Objekte auslesen

muss includiert sein

	<script type="text/javascript" src="fileadmin/templates/scripts/js/json2.js"></script>

HTML

	<div id="json">{"0":["3","4"],"2":"1","3":["1","3"]}</div>

Smarty-HTML

	<div id="json">{literal}{{/literal}"0":["3","4"],"2":"1","3":["1","3"]{literal}}{/literal}</div>

JS

	obj_json = document.getElementById('json');
	obj_json = JSON(obj_json.innerHTML);
	$j.each(obj_json,function(index,el){});

Wiki-Datei des Artikels herunterladen