我在一个网站上做一些BI工作。网页包含一些单选按钮,当用户单击包含该单选按钮的框时,将以编程方式检查这些按钮。
因此,当用户单击div时,我不能更改html或检查广播的函数。
<form>
<div><input type="radio" name="a" value="1" checked>1</div>
<div><input type="radio" name="a" value="2">2</div>
</form>
jQuery('form > div').on('click', function() {
$(this).find('input[type=radio]').prop('checked', true);
});
现在,我正在尝试编写一些代码,以便在这个页面上注入。此代码需要检测无线电更改,但除非用户单击收音机本身,否则jQuery on方法无法检测它。
jQuery('form > div').on('change', 'input[type=radio]', function() {
console.log(1234);
});
https://jsfiddle.net/e6n3roqw/
我怎么才能解决这个问题?
发布于 2016-04-11 22:48:51
只需在更改收音机的选中属性后触发更改事件,如下所示:
jQuery('form > div').on('click', function() {
var element = $(this).find('input[type=radio]');
element.prop('checked', true);
element.change();
});
发布于 2016-04-11 21:58:13
使用$(this).find('input[type=radio]').trigger('change');
https://stackoverflow.com/questions/36559995
复制相似问题