Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jQuery字段选择_Javascript_Jquery_Html_Forms - Fatal编程技术网

Javascript jQuery字段选择

Javascript jQuery字段选择,javascript,jquery,html,forms,Javascript,Jquery,Html,Forms,我甚至试过了 jQuery(document).ready(function(){ jQuery('#submit').click(function(){ var name = jQuery("#dname").val(); }); }); 为什么??脚本排队并在加载页加载。 还是娜达 在代码中,您打开了三个div标记,但只关闭了两个div标记在代码中,您打开了三个div标记,但只关闭了两个div标记您需要防止默认表单提交: jQuery(document).ready(fun

我甚至试过了

jQuery(document).ready(function(){
  jQuery('#submit').click(function(){
    var name = jQuery("#dname").val();
  });
});
为什么??脚本排队并在加载页加载。
还是娜达

在代码中,您打开了三个div标记,但只关闭了两个div标记

在代码中,您打开了三个div标记,但只关闭了两个div标记

您需要防止默认表单提交:

jQuery(document).ready(function(){
  jQuery('#submit').click(function(){
    var name = jQuery("#dname").val();
    jQuery.ajax({
      url: '/wp-admin/admin-ajax.php',
      type: 'POST',   // Adding Post method
      dataType: 'JSON',// Including ajax file
      data: {'action': 'do_search', 'dname':name}, // Sending data dname to post_word_count function.
      success: function(data){ // Show returned data using the function.
        alert(data);
      }
    });
  });
});
还是成功

jQuery('#submit').click(function(e){
  ...
  e.preventDefault();
  // or
  return false;
});
您需要防止默认表单提交:

jQuery(document).ready(function(){
  jQuery('#submit').click(function(){
    var name = jQuery("#dname").val();
    jQuery.ajax({
      url: '/wp-admin/admin-ajax.php',
      type: 'POST',   // Adding Post method
      dataType: 'JSON',// Including ajax file
      data: {'action': 'do_search', 'dname':name}, // Sending data dname to post_word_count function.
      success: function(data){ // Show returned data using the function.
        alert(data);
      }
    });
  });
});
还是成功

jQuery('#submit').click(function(e){
  ...
  e.preventDefault();
  // or
  return false;
});

我可以在那里定义var name吗?我不明白为什么不可以在那里定义var name吗?我不明白为什么不可以