jQuery太多的递归 [英] jQuery too much recursion

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

问题描述

当我单击一个LI时,我试图选择一个单选框.但是我得到太多递归"的错误.

Im trying to select a radio box when I click an LI. But i get the error "to much recursion".

代码是:

$('li').click( function(){
     $('li.selected').removeClass('selected');
     $(this).addClass('selected');
     $(this).children("input[type=radio]").click();
});

这是使用jQuery 1.4.2和UI 1.7.2.

This is using jQuery 1.4.2 and UI 1.7.2.

推荐答案

当您.child()子input .click()时,事件冒泡并重新触发li的click().您需要将.click()添加到input并在其中进行event.preventBubble=true;,否则只需设置选中的属性即可,而不是click()对其进行设置.

when you .click() the child input, the event bubbles up and re-triggers the li's click(). You need to add a .click() to the input and do event.preventBubble=true; in it, or else just set the checked property instead of click()ing it.

这篇关于jQuery太多的递归的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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