gpt4 book ai didi

javascript - JQuery 1.3.2 中的 "too much recursion"错误

转载 作者:可可西里 更新时间:2023-11-01 01:23:27 24 4
gpt4 key购买 nike

我正在尝试制作一个具有一些动态行为的表单。具体来说,我在 div 中有我的输入,我想这样当用户点击 div 中的任何地方时,输入被选中。我使用的是 JQuery 1.2.6,一切正常。

但是,我升级到 JQuery 1.3.2 后出现了一些奇怪的行为。当我点击任何输入时,我会在它被选中之前得到一个延迟。我的 Firefox 错误控制台给了我几个来自 JQuery 库的“太多递归”错误。我在 Internet Explorer 7 中尝试该页面并收到一条错误消息“对象不支持此属性或方法”。

我是不是做错了什么,或者这是 JQuery 中的错误?有谁知道在不返回旧版本的情况下修复此行为的方法?我正在使用 Firefox 3.0.7 以防万一。这是我为说明问题而制作的一个简单示例:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>quiz test</title>
<script type="text/javascript" src="jquery-1.3.2.min.js"></script>
</head>
<body>
<div class='question'>Favorite soda?
<div><input type='radio' name='q' value='A' id='a'><label for='a'>Coke</label></div>
<div><input type='radio' name='q' value='B' id='b'><label for='b'>Pepsi</label></div>
</div>
<script type="text/javascript">
$(function() {
$(".question div").click(function() {
$(this).children("input").click();
});
});
</script>
</body></html>

最佳答案

$(function() {
$(".question div").click(function() {
var radio = $(this).children("input")[0];
radio.checked = !radio.checked;
});
});

关于javascript - JQuery 1.3.2 中的 "too much recursion"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/639862/

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