这是我在这里的第一篇文章,尽管我浏览了很多答案。我遇到了一个问题,IE8 将继续抛出“Object Expected”错误。我使用了 IE8 的开发者工具,它指向“mymh.js”文件
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="/MyMHome/javascript/mymh.js"></script>
mymh.js 文件只有以下代码
$(document).ready(function() {
$('#hNumber').focus();
$('#ddlDir').change(function () {
var selVal = $('#ddlDir').val();
if (selVal == 'N' || selVal == 'S' || selVal == 'E' || selVal == 'W'){
$.getJSON('/MyMHome/DimeServlet?strDir='+$('#ddlDir option:selected').val(), function(data) {
$('#ddlSt')
.find('option')
.remove()
.end()
$.each(data, function(i,field){
var name = field;
$('#ddlSt')
.append('<option value= ' + '"' + name + '"' + '>' + name + '</option>');
});
});
$('#ddlSt').focus();
}else{
$('#ddlSt')
.find('option')
.remove()
.end()
.append('<OPTION selected value="">Choose a direction first</OPTION>');
}
})
.trigger('change');
$('#reset').click(function(){
$('#ddlSt')
.find('option')
.remove()
.end()
.append('<OPTION selected value="">Choose a direction first</OPTION>');
$('#hNumber').focus();
});
$('#hNumber').bind('keyup', function() {
if($('#hNumber').val().length == 5){
$('#ddlDir').focus();
}
});
$('#submitQuery').click(function(){
var houseNumber = $('#hNumber').val();
if(houseNumber.replace(/\s+/g, '').length == 0){
alert('Please enter a house number.');
$('#hNumber').focus();
return false;
}else if( (!$.isNumeric(houseNumber)) || houseNumber.indexOf('-') > -1 || houseNumber.indexOf('.') > -1){
alert('Please enter numbers only. You will be prompted later, if the address requires a suffix.');
$('#hNumber').focus();
return false;
}else if(houseNumber < 100 || houseNumber > 12999){
alert('Please enter a house number between 100 and 12999');
$('#hNumber').focus();
return false;
}else if($('#ddlDir option:selected').val() == 'none'){
alert('Please select a street direction.');
$('#ddlDir').focus();
return false;
}
});
$('form').keypress(function(e) {
if (e.keyCode == '13') {
e.preventDefault();
if($('#ddlSt').is(":focus")){
$('#submitQuery').trigger('click');
}
else{
return false;
}
}
});
});
错误指向<script ... mymh.js></script>
但在调试器中它指向$document.ready(function() {
任何人都认为为什么 IE8 会继续抛出该错误有什么问题?