以下是我的JavaScript(mootools)代码:
$('orderNowForm').addEvent('submit', function (event) {
event.preventDefault();
allFilled = false;
$$(".required").each(function (inp) {
if (inp.getValue() != '') {
allFilled = true;
}
});
if (!allFilled) {
$$(".errormsg").setStyle('display', '');
return;
} else {
$$('.defaultText').each(function (input) {
if (input.getValue() == input.getAttribute('title')) {
input.setAttribute('value', '');
}
});
}
this.send({
onSuccess: function () {
$('page_1_table').setStyle('display', 'none');
$('page_2_table').setStyle('display', 'none');
$('page_3_table').setStyle('display', '');
}
});
});
Run Code Online (Sandbox Code Playgroud)
在IE以外的所有浏览器中,这都可以.但在IE中,这会导致错误.我有IE8所以在使用它的JavaScript调试器时,我发现该event对象没有preventDefault导致错误的方法,因此表单已经提交.在Firefox(我发现使用Firebug)的情况下支持该方法.
任何帮助?