µÇ¼ | Ê×Ò³ -> »ªÐÂÏÊÊ -> Çóѧʨ³Ç | Çл»µ½£º´«Í³°æ / sForum | Ê÷ÐÎÁбí
Çóhtml.option.style.display IEµÄ½â¾ö°ì·¨
<<ʼҳ¡¡ [1]¡¡ Ä©Ò³>>¡¡

Çóhtml.option.style.display IEµÄ½â¾ö°ì·¨×î½ü·¢ÏÖÈç¹ûÔÚoptionÏÂÓÃstyle.displayµÄʱºò£¬ÔÚfirefoxÏÂÕý³££¬µ«ÊÇÔÚIEϾͲ»Õý³£¡£
Çë¿´
click
ÔÚfirefoxÏ£¬µã»÷ÏÂÃæµÄshow/hide£¬ÏÂÀ­²Ëµ¥»áÏàÓ¦µÄ±ä»¯£¬ÔÚIEÏÂÔò²»»á¡£
ÇëÎÊ´ïÈË£¬ÔÚIEÏÂÒªÔõô×ö²ÅÓиúfirefoxÒ»ÑùµÄЧ¹û£¿
[icky (6-17 13:34, Long long ago)] [ ´«Í³°æ | sForum ][µÇ¼ºó»Ø¸´]1Â¥

Ô­codeÈçÏÂ<html>
<head>
<script type="text/javascript">
function show_hide(id) {
if (document.getElementById(id).style.display == 'block')
document.getElementById(id).style.display = 'none';
else if (document.getElementById(id).style.display == 'none')
document.getElementById(id).style.display = 'block';
document.getElementById('opt').value = 0;
}
</script>
</head>
<body>
<div style="height: 100px"></div>
<form>
<select id="opt" name="option">
<option id="opt0" value=0 style="display: block">default</option>
<option id="opt1" value=1 style="display: block">first option</option>
<option id="opt2" value=2 style="display: block">second option</option>
<option id="opt3" value=3 style="display: block">third option</option>
<option id="opt4" value=4 style="display: block">fourth option</option>
</select>
</form>
<table>
<tr><td>
<a onclick="show_hide('opt1')">show/hide first option</a>
</td></tr><tr><td>
<a onclick="show_hide('opt2')">show/hide second option</a>
</td></tr><tr><td>
<a onclick="show_hide('opt3')">show/hide third option</a>
</td></tr><tr><td>
<a onclick="show_hide('opt4')">show/hide fourth option</a>
</td></tr>
</table>
<div style="height: 800px"></div>
</body>
</html>
[icky (6-17 13:35, Long long ago)] [ ´«Í³°æ | sForum ][µÇ¼ºó»Ø¸´]2Â¥

(ÒýÓà icky:Ô­codeÈçÏ function show_hide(id) { if (document.getElementById(id).style.display == 'block') document.getElementById(id).st...)ÕâÊÇIEµÄÒ»¸öbug£¬ Óм¸¸öworkaroundµÄ·½·¨Äã¿ÉÒÔmaintain¼¸¸öarray£¬È»ºóÿ´Î¶¼Öؽ¨ËùÓÐoptions»òÕßÓÃadd/removeÀ´¶¯Ì¬Ìí¼Ó/ɾ³ýÊÜÓ°ÏìµÄoption£º

<html>
<head>
<script type="text/javascript">
function show_hide(id, text) {
var op = document.getElementById(id);
var select = document.getElementById("opt");

if (op) {
select.remove(op.index);
return;
}

for (var i=0; i<select.length; i++) {
if (select.options[i].id > id) break;
}

op = document.createElement('option');
op.text=text;
op.id = id;

try {
select.add(op, select.options[i]); // firefox
}
catch (ex) {
select.add(op, i); // ie
}
}
</script>
</head>
<body>
<div style="height: 100px"></div>
<form>
<select id="opt" name="option">
<option id="opt0" value=0 style="display: block">default</option>
<option id="opt1" value=1 style="display: block">first option</option>
<option id="opt2" value=2 style="display: block">second option</option>
<option id="opt3" value=3 style="display: block">third option</option>
<option id="opt4" value=4 style="display: block">fourth option</option>
</select>
</form>
<table>
<tr><td>
<a onclick="show_hide('opt1', 'first option')">show/hide first option</a>
</td></tr><tr><td>
<a onclick="show_hide('opt2', 'second option')">show/hide second option</a>
</td></tr><tr><td>
<a onclick="show_hide('opt3', 'third option')">show/hide third option</a>
</td></tr><tr><td>
<a onclick="show_hide('opt4', 'fourth option')">show/hide fourth option</a>
</td></tr>
</table>
<div style="height: 800px"></div>
</body>
</html>
[´óÊ÷Ï (6-17 15:21, Long long ago)] [ ´«Í³°æ | sForum ][µÇ¼ºó»Ø¸´]3Â¥

(ÒýÓà icky:Ô­codeÈçÏ function show_hide(id) { if (document.getElementById(id).style.display == 'block') document.getElementById(id).st...)½¨ÒéÓÃJSµÄframework, JQuery, Prototype ¶¼²»´í
[moon9shine (6-17 16:41, Long long ago)] [ ´«Í³°æ | sForum ][µÇ¼ºó»Ø¸´]4Â¥

(ÒýÓà ´óÊ÷ÏÂ:ÕâÊÇIEµÄÒ»¸öbug£¬ Óм¸¸öworkaroundµÄ·½·¨Äã¿ÉÒÔmaintain¼¸¸öarray£¬È»ºóÿ´Î¶¼Öؽ¨ËùÓÐoptions»òÕßÓÃadd/removeÀ´¶¯Ì¬Ìí¼Ó/ɾ³ýÊÜÓ°Ïìµ...)¸óÏÂÕæÄËÉñÈËÒ²[icky (6-17 17:31, Long long ago)] [ ´«Í³°æ | sForum ][µÇ¼ºó»Ø¸´]5Â¥


<<ʼҳ¡¡ [1]¡¡ Ä©Ò³>>¡¡
µÇ¼ | Ê×Ò³ -> »ªÐÂÏÊÊ -> Çóѧʨ³Ç | [ˢб¾Ò³] | Çл»µ½£º´«Í³°æ / sForum