这是我的代码。此代码不适用于 mozilla firefox 浏览器。
我的 HTML
<input class="staff_check" name="select_staff" type="checkbox" value="@Model.Caregivers[i].AgencyUserID" />
脚本
var selected_staff = [];
var selected_staff_names = [];
$('input[name="select_staff"').change(function () {
console.log('ds');
if (this.checked) {
selected_staff.push($(this).val());
selected_staff_names.push('<span class="selected_staff">' + $(this).parent('label').text().trim() + '</span>');
}
else {
var idx = $.inArray($(this).val(), selected_staff);
if (idx > -1) {
selected_staff.splice(idx, 1);
selected_staff_names.splice(idx, 1);
}
}
});
这在谷歌浏览器中运行良好。但它在 mozilla firefox 中不起作用。
最佳答案
你错过了结束方括号']
',更改:
...
$('input[name="select_staff"').change(function () {
....
到
...
$('input[name="select_staff"]').change(function () {
...
关于javascript - 复选框更改事件在 firefox jquery 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27598311/