Javascript 防止页面加载时触发Onchange事件
我正在使用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
$("#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>