我需要手动检查我的单选按钮,如下所示。但问题是该事件没有被触发(手动检查时)。
$(function () {
// always check the 1st element
$("input:radio[name=MatrixID]:first").attr('checked', true).click();
});
$('.editor-field > input[type=radio]').change(function () {
// !!! not fired when checked by code!!??
p.mustSave = true;
});
我的问题:如何手动(通过代码)检查我的单选按钮并触发更改事件?
我的html:
<p>
<span class="editor-field">
<input name="MatrixID" id="MatrixID873" type="radio" checked="checked" value="873"/>
</span>
</p>
非常感谢。
最佳答案
.click()
触发点击事件,但您正在使用 change()
。试试这个:
$("input:radio[name=MatrixID]:first").prop('checked', true).trigger('change');
关于javascript - 通过代码检查我的单选按钮并触发更改事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19641106/