Javascript 仅在IE上,表单DOM id返回;是否为空或不是对象;问题
你可以在这里看到我的代码 相对于Javascript 仅在IE上,表单DOM id返回;是否为空或不是对象;问题,javascript,dom,javascript-events,Javascript,Dom,Javascript Events,你可以在这里看到我的代码 相对于 onmouseover="document.challengeitems.mySelect.options[1].selected=true" 虽然选项[1](如果在变量中,则为选项[x])可以在所有范围内工作,但您可以看到一个问题,即无法反复单击它(鼠标移出然后单击) 我只希望每个选择都单击一次。您有一个ID,所以直接转到它 document.getElementById('piece03').setAttribute("selected","true")
onmouseover="document.challengeitems.mySelect.options[1].selected=true"
虽然选项[1](如果在变量中,则为选项[x])可以在所有范围内工作,但您可以看到一个问题,即无法反复单击它(鼠标移出然后单击)
我只希望每个选择都单击一次。您有一个ID,所以直接转到它
document.getElementById('piece03').setAttribute("selected","true")
JS中的事件对象包含指向触发事件的元素的链接。如果我正确理解了你的问题,你会得到如下结果:
<select multi height="xxx">
<option value="1" onmouseover="...">1</option>
<option value="2" onmouseover="...">2</option>
<option value="3" onmouseover="...">3</option>
</select>
1.
2.
3.
你可以使用
onmouseover=“event.target.selected=true;
来代替,这样你就不用为每次鼠标悬停都在哪个元素上进行编码了。onmouseover=“for(var i=0;ii)刚开始在stackoverflow.com上运行,我已经很喜欢它了!我认为它比任何东西都好。工作中的信誉货币。我只需要学习如何更好地驾驭它。失去了我的其他评论。。我在写:我只是插入了迪奥多斯的代码,瞧!没有更多的IE错误。当他返回多个选择时,我不得不像我以前的dom代码一样对其进行哑处理,但可能是因为我没有始终如一地插入它。在任何情况下,您都可以在此处看到固定代码-。另外,我直到后来才见到他们,但我也要感谢其他人的回答!啊!但现在我看到,一旦单击某个项目,它就会从第一个列表中消失,再次返回错误!该死的。
onmouseover="for(var i=0; i<document.challengeitems.mySelect.options.length; i++)
{if (document.challengeitems.mySelect.options[i].id=='piece01')
document.challengeitems.mySelect.options[i].selected=true;}"
<select multi height="xxx">
<option value="1" onmouseover="...">1</option>
<option value="2" onmouseover="...">2</option>
<option value="3" onmouseover="...">3</option>
</select>
onmouseover="for(var i=0; i<document.challengeitems.mySelect.options.length; i++)
{if (document.challengeitems.mySelect.options[i].id=='piece01')
document.challengeitems.mySelect.options[i].selected=true;}"