【问题标题】:jquery AJAX and event handlersjquery AJAX 和事件处理程序
【发布时间】:2016-07-06 07:32:48
【问题描述】:

我在这里找到了一些关于事件处理程序和事件委托的线程,这些线程与使用 ajax 动态加载的内容有关。

我有一个项目,我们从外部资源加载表单。这必须使用 ajax 来完成,但我们需要检测一些 html 元素上的点击事件。

通常我们将事件委托附加到最近的静态元素,但由于这是代码的实际空容器,我们无法定位其中的元素。

    jQuery(function(){
            console.log(jQuery('#feedbackCollect-form-container'));
            jQuery('.form-item.form-item-field-fc-found-data-und.form-type-radio.radio').on('click', '#feedbackCollect-form-container',function(){
            jQuery('.form-item.form-item-field-fc-found-data-und.form-type-radio.radio').removeClass('feedback-active');
            jQuery(this).addClass('feedback-active');
            });
    });

我该如何解决这个问题?

【问题讨论】:

    标签: jquery ajax drupal-7


    【解决方案1】:

    将事件监听器附加到body标签:

    jQuery(function(){
                jQuery('body').on('click', '#feedbackCollect-form-container',function(){
                jQuery('.form-item.form-item-field-fc-found-data-und.form-type-radio.radio').removeClass('feedback-active');
                jQuery(this).addClass('feedback-active');
                });
        });
    

    【讨论】:

      猜你喜欢
      • 2014-09-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多