简体   繁体   English

jQuery在HTML单选按钮上触发调用后未捕获点击事件

[英]jQuery not capturing click event following trigger call on HTML radio button

I have a very strange issue with jQuery where I am triggering a click on a radio button but it is not firing completely and is not being captured by an on click function, however a similar call to jQuery trigger is being captured. 我有jQuery的一个很奇怪的问题,我在哪里触发单选按钮点击,但它并没有完全开火,而不是被一个捕捉on点击功能,但类似的调用jQuery的trigger 抓获。

In the following jQuery I am selecting a <div> and using find to search for the suitable content. 在下面的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);

These are my radio buttons: 这些是我的单选按钮:

<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
});

I can't see how jQuery is able to select the radio button and successfully check it, but the on method doesn't pick it up as a click...especially when I have a very similar setup running in close proximity in the code. 我看不到jQuery如何能够选择单选按钮并成功检查它,但是on方法不会将其作为单击...特别是当我在代码中非常接近地运行一个非常类似的设置时。

I know for sure that the radio buttons are within the selector as I can dump it out to the console with a console.log . 我肯定知道单选按钮在选择器中,因为我可以使用console.log将其转储到控制台中。 Interestingly, when I dump out the events attached to it to the console I get undefined from this after the trigger : 有趣的是,当我将与它关联的事件转储到控制台时trigger 之后 ,我对此undefined

console.log(prev_chosen_d_option.find("#_standard_use_b_as_s_no").data('events'));

(I am using jQuery 1.7.2 and testing in FF). (我正在使用jQuery 1.7.2并在FF中进行测试)。

Instead of 代替

    $('input[name=del_standard_use_b_as_s], input[name=del_next_day_use_b_as_s], #del_standard_use_b_as_s_no').on('click', function(e) {
//
    });

Try : 尝试:

$(document).on('click', 'input[name=del_standard_use_b_as_s], input[name=del_next_day_use_b_as_s], #del_standard_use_b_as_s_no', function(e) {
 // 
});

导致此操作不起作用的原因很简单,就是我在代码中实际触发点击的位置下方有点击处理程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM