简体   繁体   English

JQUERY 单击 function 在 javascript 文件中不起作用

[英]JQUERY Click function not working inside javascript file

JQUERY on Click function not working inside JavaScript file of WordPress AJAX Call. JQUERY on Click function not working inside JavaScript file of WordPress AJAX Call. The function alert() outside of the click function is working.点击 function 之外的 function alert() 正在工作。 But inside not, But everything setup okay for AJAX Call.但是内部没有,但是 AJAX 调用的一切设置都可以。 the script file called correctly in the webpage.在网页中正确调用的脚本文件。

var columnfiltertext, column_filter_number;
jQuery(document).ready(function(){
  //jQuery('span.filter-option').on('DOMSubtreeModified',function(){
  jQuery('span.filter_column.filter_select').click(function(){
    alert("okay");
    column_filter_number = jQuery(this).attr("data-index");
    columnfiltertext = jQuery(this).find("span.filter-option").text();
    if(columnfiltertext)
    {
      if(columnfiltertext != " ")
      {
        //document.cookie = "columnfiltertext= ; expires = Thu, 01 Jan 1970 00:00:00 GMT";
        //setCookie("columnfiltertext", columnfiltertext , 1);
        //alert("Cookie is: " + getCookie("columnfiltertext"));
        if(column_filter_number)
        {
          alert(column_filter_text); 
          //alert(column_filter_number);
        }
      }
    }
    jQuery.ajax({
      url: example_ajax_obj.ajaxurl,
      data: {
        'action': 'example_ajax_request',
        'fruit' : fruit,
        'nonce' : example_ajax_obj.nonce
      },
      success:function(data) {
        // This outputs the result of the ajax request
        //console.log(data);
        alert(data);
      },
      error: function(errorThrown){
        //console.log(errorThrown);
        alert(errorThrown);
      }
    });  
  });
});

Filename: simple-ajax-example.js文件名:simple-ajax-example.js

If your alert("okay") is not reachable, then it might be the case that your selector ie jQuery('span.filter_column.filter_select') might not be returning anything.如果您的 alert("okay") 无法访问,则可能是您的选择器,即jQuery('span.filter_column.filter_select')可能没有返回任何内容。 You may try that in your browser console if it returns anything, just past jQuery('span.filter_column.filter_select') in console if your DOM is already rendered.如果它返回任何内容,您可以在浏览器控制台中尝试,如果您的 DOM 已经呈现,则在控制台中通过jQuery('span.filter_column.filter_select')

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

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