我写了这段代码:
function validateForm(){
if (document.getElementById('user_login') != null ){
var user_login = document.getElementById('user_login');
if(user_login.value == ''){
user_login.style.backgroundColor = "red";
user_login.focus();
return false;
}
}
}
function goToSec(){
if(validateForm()){
var first = document.getElementById('first');
first.style.display = 'none';
var second = document.getElementById('second');
second.style.display = 'block';//in firfox this line will execute
}
}
当事件运行goToSec()
时,在Firefox中,如果validateForm()
返回false
,最后一行代码行将被执行但是在chrome中一切正常,程序控制将会消失代码块。
我用简单的脚本测试了它,例如:
function f(){
return false;
}
function boo(){
if(f()){
alert('1');
alert('2');//debuger meets this line but the code wont be exeuted
}
}
<button onclick="boo()">Ok</button>
用firefox debuger调试它我发现了一些奇迹,这次debuger遇到这条线但是不会执行它 firefox是如何工作的?以及我们如何处理它?</ p>