gpt4 book ai didi

javascript - 尝试在单选按钮上获取鼠标悬停事件

转载 作者:行者123 更新时间:2023-11-28 19:41:35 24 4
gpt4 key购买 nike

当我将鼠标悬停在单选按钮上时,我试图调用一个函数。该函数永远不会被调用。下面两个单选按钮中的第一个显示了我的最新尝试。

<form action="#">
<ul>
<li>
<input type="radio" class="button" name="buttonSubGroup" onclick="Door();" onmouseover="mouseOver('doorMouseover')" onmouseout="mouseOff('doorMouseover')" id="button1" checked/>
<label for="button1">Door</label>
</li>
<li>
<input type="radio" class="button" name="buttonSubGroup" onclick="Trim();" id="button2" />
<label for="button2">Trim</label>
</li>
<li>
<input type="radio" class="button" name="buttonSubGroup" onclick="Roof();" onmouseover="mouseOver('roofMouseover');" onmouseout="mouseOff('roofMouseover');" id="button3" />
<label for="button3">Roof</label>
</li>
<li>
<input type="radio" class="button" name="buttonSubGroup" onclick="Siding();" id="button4" />
<label for="button4">Siding</label>
</li>
<li>
<input type="radio" class="button" name="buttonSubGroup" onclick="Stone();" id="button5" />
<label for="button5">Stone</label>
</li>
<li>
<input type="radio" class="button" name="buttonSubGroup" onclick="BB();" id="button6" />
<label for="button6">BB</label>
</li>
</ul>
</form>

编辑:

这是我的 JS 函数。我设置了一个警报,以便在我进入该函数时通知我。

function mouseOver(a) {
alert(a)
document.getElementById(a).style.visibility = 'visible';
}

function mouseOff(a) {
alert(a);
document.getElementById(a).style.visibility = 'hidden';
}

最佳答案

我注意到两件事:

1.第一个单选按钮上的选中属性应为 check="checked"

2.当将鼠标悬停在单选按钮上时,此代码似乎可以工作。如果您希望它在将鼠标悬停在标签上时起作用,您还需要向标签添加 onmouseover 和 onmouseout 事件处理程序。例如:

<li>
<input type="radio" class="button" name="buttonSubGroup" onclick="Door();" onmouseover="mouseOver('doorMouseover')" onmouseout="mouseOff('doorMouseover')" id="button1" checked="checked"/>
<label for="button1" onmouseover="mouseOver('doorMouseover')" onmouseout="mouseOff('doorMouseover')>Door</label>
</li>

http://jsfiddle.net/puddinman13/Mh7PZ/

关于javascript - 尝试在单选按钮上获取鼠标悬停事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24916342/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com