Javascript 校验页面内容后,页面还是会提交??
代码如下:
function submit1_onclick() {
var str = document.getElementById( 'hObligatory ').value;
if (str == " " ){
alert( "please select accessories¡£ ");
document.getElementById( 'hObligatory ').focus();
return false;
}
return window.confirm( "Are you sure? ");
}
<INPUT class= "button " id= "Submit1 " type= "submit " value= "Add to Shopping Cart " name= "ButtonSubmit ">
每次单击button都会弹出提示窗口,但点击提示窗口的‘确定’后页面还是会触发提交事件,请教高手,这是为什么??
onclick= "return submit1_onclick() ">
------解决方案-------------------- <INPUT class= "button " id= "Submit1 " type= "submit " value= "Add to Shopping Cart " name= "ButtonSubmit ">
把这里的type= "submit " 改成type= "button "