onclick事件中checkForm()和return checkForm()的区别
先上代码: <!DOCTYPE html> < html > < head > < title > test </ title > </ head > < body > < div > < a href = "www.baidu.com" onclick = "return checkForm()" > 点击我 </ a > </ div > </ body > </ html > < script type = "text/javascript" > function checkForm () { return true ; } </ script > 测试结果:测试发现,onclick里加return时,checkForm()方法必须返回true才可以触发a标签的跳转。而不加return的时候,无论checkForm()返回false还是true,都会触发a标签的跳转。 来源: CSDN 作者: yangSnowy 链接: https://blog.csdn.net/m0_37742748/article/details/80596923