我在表单中有一个具有不同选项的select元素。 'select'的属性是onchange="testRecurrence(this.form)"
,js函数只是:
function testRecurrence(form) {
if(form.repeat.value != "N") {
form.endR.style.display = 'inline';
}
return true;
}
在选项值不是“N”的情况下,重复'select'和'endR'我要显示的项目。这里的问题是,这不起作用......一直试图找到解决方案,但不能。有什么帮助吗?
更新
不工作,元素始终隐藏。默认情况下,元素endR为display:none
。
UPDATE2 js函数改为:
function testRecurrence(form) {
if(form.repeat.options[form.repeat.selectedIndex].value != 'N')
document.getElementById('endR').style.display = 'inline';
}
HTML:
<select name="repeat" onchange="testRecurrence(this.form)">
...
<div id="endR" style="display: none">
...
</div>
现在有效。谢谢。
答案 0 :(得分:3)
我认为获取select元素的值并不适用于所有浏览器,但这应该是:
form.repeat.options[form.repeat.selectedIndex].value