“过多的递归” JQuery 1.3.2中的错误 [英] "too much recursion" error in JQuery 1.3.2

查看:71
本文介绍了“过多的递归” JQuery 1.3.2中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作一些具有动态行为的表单。具体来说,我在div中输入了输入,我希望当用户点击div中的任意位置时,输入就会被选中。我使用的是JQuery 1.2.6,一切正常。

I am trying to make a form with some dynamic behavior. Specifically, I have my inputs in divs, and I would like to make it so when the user clicks anywhere in the div, the input is selected. I was using JQuery 1.2.6 and everything worked fine.

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

However, I upgraded to JQuery 1.3.2 and I am getting some strange behavior. When I click on any of the inputs, I get a delay before it is selected. My Firefox error console gives me several "too much recursion" errors, from within the JQuery library. I tried the page in Internet Explorer 7 and got an error saying "Object doesn't support this property or method".

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

Am I doing something wrong, or is this a bug in JQuery? Does anyone know a way to fix this behavior, without going back to the old version? I am using Firefox 3.0.7 in case that matters. Here is a simple example I made to illustrate the problem:

<!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>


推荐答案

谢谢大家。我尝试了grillix设置checked属性的想法,虽然我不得不修改一下语法。这就是我做的:

Thank you all. I tried grillix's idea of setting the checked attribute, although I had to fix up the syntax a little bit. Here is what I did:

$(this).children("input").attr("checked", true);

它有效,但我仍然很好奇为什么我以前的方式停止使用JQuery 1.3.2 。我知道事件冒泡行为的变化,但为什么我不能通过在回调中调用event.stopPropagation()或return false来解决这个问题?

It works, but I am still curious as to why my previous way stopped working with JQuery 1.3.2. I know about the changes in event bubbling behavior, but why can't I fix that by calling "event.stopPropagation()" or "return false" within my callback?

这篇关于“过多的递归” JQuery 1.3.2中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆