我试图对用户单击执行输入验证。然而,jQuery的click()函数一直工作不稳定;有时它会像我期望的那样工作,有时点击链接除了将视口移动到屏幕顶部之外什么也不做。问题是我不能一致地复制错误;有时会起作用,有时却不起作用。我已经在Windows XP和Mac 9.0上的Firefox 9.0中复制了它,但是,有时该页面可以正常工作,有时不会。有一次,当它加载不正确时,我尝试清除缓存,并再次加载页面,并且页面仍然没有加载。它似乎从没有加载到加载,特别是在对文件进行大的修改之后。jquery click()工作不一致
我在这里设置了一个简化测试用例:http://kburke.org/thesis/consentform1.php。如果表单工作正常,它应该显示一个警告框。这里是代码:
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#submitlink").click(function(){
console.log("link clicked");
alert("Clicked!");
});
console.log("loading...");
});
</script>
</head>
<body style="width:35em; margin-bottom:200px;">
<input type="text" value="" name="part_name" id="name1" />
<input type="text" value="" name = "part_name2" id="name2" />
<input type="checkbox" name="accept_1" id="accept_1" />I signify my agreement that all matters and issues mentioned above have been discussed to my satisfaction and agreement. <br><br>
<input type="checkbox" name="accept_2" id="accept_2" />I acknowledge that I am 18 years of age or older on the date of signing this consent, and that I have read and understood all of the above.</p>
<div id="submitlink" style="float:right; color:blue; text-decoration:underline; cursor:pointer;">I agree</div>
<form method="post" id="agree" action="/thesis/instructions.php">
<input type="hidden" name="id" id="nextpage" value="">
<input type="hidden" name="name" id="the_name" value="" />
</form>
</body>
</html>
谢谢你的任何见解,你可能有,我特别是困惑,行为是不一致的。
编辑:有人建议console.log
导致的问题,但我在移除控制台语句后仍然有问题。运行Chrome的JS调试器表明,$("#submitlink")
调用中的代码在发生问题时根本没有运行。像往常一样,我感谢你的帮助。
产生错误的整页是在这里:http://kburke.org/thesis/consentform.php页面上 – 2010-11-21 04:44:13
链路工作就好在我的Chrome浏览器。 .. – Lukman 2010-11-22 03:17:55
对于我来说,当前版本(它不起作用)是Mac上的Chrome 7.0。我也把它缩小到最小的情况下,它仍然不适合我。 – 2010-11-22 03:22:41