Přidat otázku mezi oblíbenéZasílat nové odpovědi e-mailemVyřešeno nefunkcni javascript (css) v ie

ie.htm

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
   "www.w3.org/TR/html4/strict.dtd">
<html>
<head>
	<title>Formular</title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

	<script type="text/javascript">	
		function zobraz(zob_id)
		{
			switch (zob_id)
			{
			case '1':
				document.getElementById('id1').setAttribute("style", "display:block");
				document.getElementById('id2').setAttribute("style", "display:none");
				break;
			case '2':
				document.getElementById('id1').setAttribute("style", "display:none");
				document.getElementById('id2').setAttribute("style", "display:block");
				break;
			case '0':
				document.getElementById('id1').setAttribute("style", "display:none");
				document.getElementById('id2').setAttribute("style", "display:none");
				break;
			default:
				break;
			}
		}
	</script>

	<style type="text/css">
		.hidden{display:none}
	</style>
</head>

<body>
    <form action="" method="POST">
    <div>
		Zobraz 1<input type="radio" name="typ" value="1" onclick="zobraz('1')"> /&nbsp;
		Zobraz 2<input type="radio" name="typ" value="2" onclick="zobraz('2')"> /&nbsp;
		Schovej<input type="radio" name="typ" value="0" onclick="zobraz('0')">
		<br><br>
		<div id="id1" class="hidden">
		    Moznost 1
		</div>
		<div id="id2"  class="hidden">
		    Moznost 2
		</div>
    </div>
    </form>
</body>
</html>
Předmět Autor Datum
Nefunguje to v ie a numuzu prijit na to proc. Odmita zobrazit ty DIVy. V jinych prohlizecich to fung… nový
foltyn 04.03.2006 17:26
foltyn
Neviem prečo, ale takto to bere aj IE aj FF. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "www… nový
Genio 04.03.2006 17:55
Genio
Jednoducho povedané setAttribute pre style v IE nefunguje (viac napr. na http://www.quirksmode.org/b… nový
los 04.03.2006 19:50
los
diky za rady 4los: dalsi nebudou :)) poslední
foltyn 05.03.2006 23:52
foltyn

Neviem prečo, ale takto to bere aj IE aj FF.

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
   "www.w3.org/TR/html4/strict.dtd">
<html>
<head>
	<title>Formular</title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

	<script type="text/javascript">
		function zobraz(zob_id)
		{
			switch (zob_id)
			{
			case '1':
				document.getElementById('id1').style.display = "block";
				document.getElementById('id2').style.display = "none";
				break;
			case '2':
				document.getElementById('id1').style.display = "none";
				document.getElementById('id2').style.display = "block";
				break;
			case '0':
				document.getElementById('id1').style.display = "none";
				document.getElementById('id2').style.display = "none";
				break;
			default:
				break;
			}
		}
	</script>

	<style type="text/css">
		.hidden{display:none}
	</style>
</head>

<body>
    <form action="" method="POST">
    <div>
		Zobraz 1<input type="radio" name="typ" value="1" onclick="javascript:zobraz('1')"> /&nbsp;
		Zobraz 2<input type="radio" name="typ" value="2" onclick="javascript:zobraz('2')"> /&nbsp;
		Schovej<input type="radio" name="typ" value="0" onclick="javascript:zobraz('0')">
		<br><br>
		<div id="id1" class="hidden">
		    Moznost 1
		</div>
		<div id="id2"  class="hidden">
		    Moznost 2
		</div>
    </div>
    </form>
</body>
</html>

Jednoducho povedané setAttribute pre style v IE nefunguje (viac napr. na http://www.quirksmode.org/bugreports/archives/2005/ 03/setAttribute_does_not_work_in_IE_when_used_with_ th.html).

Ešte jedno rýpnutíe k funkcii zobraz: Ak bude možností viac, bude sa stále meniť kód?

[js]function zobraz (zob_id)
{
for (var i = 1; i < 3; ++i)
document.getElementById ("id" + i).style.display = (zob_id == i? "": "none");
}[/js]

A potom neposielať funkcii zobraz v argumente reťazec, ale číslo:

<input type="radio" name="typ" value="1" onclick="zobraz(1)">

Zpět do poradny Odpovědět na původní otázku Nahoru