【发布时间】:2013-06-19 21:41:36
【问题描述】:
我对 jQuery 有一个非常奇怪的问题,我触发了对单选按钮的点击,但它没有完全触发,也没有被 on 点击函数捕获,但是对 jQuery trigger 的类似调用 正在被捕获。
在下面的 jQuery 中,我选择了 <div> 并使用 find 搜索合适的内容。
var prev_chosen_d_option = $('#d_options_table .d_option_row[data-option-id="' + d_option_for_jq + '"]');
// this works, and the on click is captured
prev_chosen_d_option.find('.hover_target').trigger("click", true);
// this selects the radio button, but DOES NOT fire the on click function seen below
prev_chosen_d_option.find('#d_standard_use_b_as_s_no').trigger("click", true);
这些是我的单选按钮:
<input type="radio" value="yes" id="d_standard_use_b_as_s_yes" name="d_standard_use_b_as_s">
<input type="radio" value="no" id="d_standard_use_b_as_s_no" name="d_standard_use_b_as_s">
$("#d_options_table .d_option_row .hover_target").on("click", function(e, isFirstLoad) {
// it comes in here fine!
});
$('input[name=d_standard_use_b_as_s], input[name=d_next_day_use_b_as_s], #del_standard_use_b_as_s_no').on("click", function(e, isFirstLoad) {
// it DOESN'T come in here
});
我看不到 jQuery 是如何选择单选按钮并成功检查它的,但是 on 方法并没有将其作为点击来选择...尤其是当我有一个非常相似的设置正在运行时在代码中很接近。
我确定单选按钮位于选择器中,因为我可以使用 console.log 将其转储到控制台。有趣的是,当我将附加到它的事件转储到控制台时,我从这个 after trigger 得到 undefined:
console.log(prev_chosen_d_option.find("#_standard_use_b_as_s_no").data('events'));
(我正在使用 jQuery 1.7.2 并在 FF 中进行测试)。
【问题讨论】:
标签: javascript jquery onclick radio-button eventtrigger