Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/88.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 防止页面加载时触发Onchange事件_Javascript_Jquery_Html - Fatal编程技术网

Javascript 防止页面加载时触发Onchange事件

Javascript 防止页面加载时触发Onchange事件,javascript,jquery,html,Javascript,Jquery,Html,我正在使用Onchange事件,它运行良好。但我希望它能防止页面加载触发 $("#first").change(function(){ $("#salary").val(function () { return $(this).find('option').filter(function () { return $(this).prop('null'); }).val(); }); }); 有人能用这段代码帮助实现这一点吗 提前感谢。您可以在此url

我正在使用Onchange事件,它运行良好。但我希望它能防止页面加载触发

$("#first").change(function(){
   $("#salary").val(function () {
    return $(this).find('option').filter(function () {
      return $(this).prop('null');
        }).val();
 });
});
有人能用这段代码帮助实现这一点吗

提前感谢。

您可以在此url中阅读并解析

<html>
 <head>
  <script src="https://code.jquery.com/jquery-1.9.1.min.js"></script>
  <script>
  $( document ).ready(function() {
      console.log( "document loaded" );
  });

  $( window ).on( "load", function() {
      console.log( "window loaded" );
  });
  </script>
 </head>
</html>

$(文档).ready(函数(){
控制台日志(“加载的文档”);
});
$(窗口).on(“加载”,函数(){
控制台日志(“窗口加载”);
});

$(窗口).on(“加载”,函数(){
$(“#first”).change(函数(){
$(“#工资”).val(函数(){
返回$(this).find('option').filter(函数(){
返回$(this.prop('null');
}).val();
});
});
});

这一点尚不清楚。请分享一个不清楚的地方?例如,你说的这个短语是什么意思:页面加载时事件触发。您共享的代码不会触发任何东西,只需绑定更改事件。您编写的代码不会在页面加载时触发,而是在更改#first时触发。那么你的问题是什么?@GuruprasadRao这是有道理的,但正如你所说的,OP必须清楚。
<html>
 <head>
  <script src="https://code.jquery.com/jquery-1.9.1.min.js"></script>
</head>
<script>
$( window ).on( "load", function() {
   $("#first").change(function(){
    $("#salary").val(function () {
      return $(this).find('option').filter(function () {
        return $(this).prop('null');
        }).val();
    });
  });
});
</script>
</html>