对象预期IE8 JS / JQuery问题IE8 [英] Object Expected IE8 JS/JQuery issue IE8
问题描述
这是我在这里的第一篇文章,虽然我浏览了很多答案。我遇到一个问题,IE8将继续抛出对象预期错误。我使用IE8的开发人员工具,它指向mymh.js文件
This is my first post on here though I browse through SO a lot for answers. I'm running into a problem where IE8 will keep throwing "Object Expected" error. I used IE8's Developer tools and it points to "mymh.js" file
<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文件只有以下代码
mymh.js file only has the following code
$(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(){
The error points to the <script ... mymh.js></script>
but in the debugger it points to $document.ready(function() {
任何人都知道为什么IE8会继续抛出该错误?
Anyone see anything wrong as to why IE8 would keep throwing that error?
推荐答案
尝试在分号处放置分号第16行结束
Try placing a semicolon at the end of line 16
来自
$('#ddlSt')
.find('option')
.remove()
.end()
$.each(data, function(i,field){
到
$('#ddlSt')
.find('option')
.remove()
.end();
$.each(data, function(i,field){
这篇关于对象预期IE8 JS / JQuery问题IE8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!