以下是我的 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', '');
}
});
});
在除了IE以外的所有浏览器中,这个代码运行正常。但是在IE中,会引发一个错误。我使用IE8的JavaScript调试器找到问题所在: event
对象没有 preventDefault
方法导致了这个错误,所以表单被提交了。而在Firefox中,这个方法是可以使用的(我通过使用Firebug发现的)。
有人能够提供帮助吗?