[英]why isn't my simple function doing return false working?
<form id="form1" onsubmit="return hi(this);">
#1 #1
function hi(bla){
console.log("abc");
return false
}
#2 #2
function hi(bla){
console.log(abc);
return false
}
issue is, in #1 the function works perfectly while in #2 the page gets refreshed and i can't see where the issue is.问题是,在 #1 中,该功能运行良好,而在 #2 中,页面刷新,我看不到问题出在哪里。 i'd like to log a variable in the console in that function.
我想在该函数的控制台中记录一个变量。
thank you for your time.感谢您的时间。
You need to set the variable abc first.您需要先设置变量 abc。 Put this before your existing code:
将其放在现有代码之前:
var abc;
As @mediaguru said the current code is missing.正如@mediaguru 所说,缺少当前代码。
var abc;
in #1在#1
function hi(bla){
console.log("abc");
return false
}
calling打电话
hi();
will console log "abc"将控制台记录“abc”
I believe you want to change #2 to我相信您想将 #2 更改为
function hi(bla){
console.log(bla);
return false
}
and then you want to call然后你想打电话
hi("abc")
to display "abc" in your console.在控制台中显示“abc”。
or more full example或更完整的例子
function hi(bla){
console.log("abc");
}
var abc = "hi"
hi(abc)
// "hi"
You can go on to debug the value of this from there.您可以从那里继续调试 this 的值。
<form id="form1" onsubmit="return hi(this);">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.