gpt4 book ai didi

javascript - 为什么这个事件总是被解雇?

转载 作者:行者123 更新时间:2023-12-02 19:02:47 28 4
gpt4 key购买 nike

此脚本检查表单是否已正确填写,但 toggle() 函数不断被触发(至少在 FireFox 中)。在下面的示例中,“现在在这里”在表单有效后不断显示(即所有字段都有一些文本)。

<script type="text/javascript">
<!--
function toggle()
{
if(document.getElementById('username').value.length > 1 && document.getElementById('pw1').value.length > 1 && document.getElementById('pw2').value.length > 1 && (document.getElementById('pw1').value == document.getElementById('pw2').value))
{
alert("now here")
document.getElementById('submit').disabled = false
}
}
//-->
</scipt>
Username:<input type="text" name='username' id='username' maxlength="30" onkeyup="toggle()"/><br />
Password:<input type="password" name="pw1" id="pw1" onkeyup="passwordCheck(document.getElementById('pw1'), document.getElementById('pw2')); toggle()"/><br />
Confirm password:<input type="password" name="pw2" id="pw2" onkeyup="passwordCheck(document.getElementById('pw1'), document.getElementById('pw2')); toggle()"/>

我很受伤,为什么onkeyup总是被解雇?就好像用户的手指永远不会离开按键一样。是否因为 onkeyup 在触发警报窗口时搞砸了,因为焦点从文本字段更改到窗口,而当按下“确定”时焦点又变回文本字段?

更新:我found it here在布吉拉。您可以vote for it 。 2001年底就报道了,为什么这么久还没有修复???

最佳答案

看起来您希望该功能在正确填写表单时将提交从禁用更改为启用。每次使用所有三个输入调用 onKeyUp 时,该函数都应该触发,因为您在所有三个输入中调用它。

当 if 语句的所有条件都正确时,我的 jsfiddle ( http://jsfiddle.net/BhaeG/ ) 仅触发 alert("now here")

除非我真的错过了一些东西,否则它看起来就像设计的那样工作。

关于javascript - 为什么这个事件总是被解雇?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14636111/

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