我的代码适用于I.E. 9,Chrome和Safari,但是很多人在使用旧版本的Internet Explorer和当前版本的Firefox时遇到了问题。它会按预期显示下拉选项,但不允许用户单击选择。这是代码:
<script type="text/javascript" src="js/jquery-1.6.2.js"></script>
<script type="text/javascript" src="js/jquery.ui.core.js"></script>
<script type="text/javascript" src="js/jquery.ui.datepicker.js"></script>
<script type="text/javascript" src="js/jquery.ui.widget.js"></script>
<script type="text/javascript" src="js/jquery.ui.position.js"></script>
<script type="text/javascript" src="js/jquery.ui.autocomplete.js"></script>
<link type="text/css" href="css/jquery-ui-1.8.17.custom.css" rel="Stylesheet" />
<style>
.ui-autocomplete-loading { background: white url('images/ui-anim_basic_16x16.gif') right center no-repeat; }
</style>
<script>
$(function() {
function log( message ) {
$( "<div/>" ).text( message ).prependTo( "#inputString" );
$( "#inputString" ).scrollTop( 0 );
showCar(message);
}
$( "#inputString" ).autocomplete({
source: "ajax/search.php",
minLength: 1,
select: function( event, ui ) {
log( ui.item ?
"Selected: " + ui.item.value :
"Nothing selected, input was " + this.value );
}
});
});
</script>
使用开发工具,它在控制台中显示此错误:SCRIPT65535:意外调用方法或属性访问。 jquery-1.6.2.js,5609行5字符
指出这一点:
prepend: function() {
return this.domManip(arguments, true, function( elem ) {
if ( this.nodeType === 1 ) {
this.insertBefore( elem, this.firstChild );
}
});
},
修改 现在它抛出一个错误说:SCRIPT438:Object不支持属性或方法'prepend' jquery-1.6.2.js,5975行4字符
是:
jQuery.each({
appendTo: "append",
prependTo: "prepend",
insertBefore: "before",
insertAfter: "after",
replaceAll: "replaceWith"
}, function( name, original ) {
jQuery.fn[ name ] = function( selector ) {
var ret = [],
insert = jQuery( selector ),
parent = this.length === 1 && this[0].parentNode;
if ( parent && parent.nodeType === 11 && parent.childNodes.length === 1 && insert.length === 1 ) {
insert[ original ]( this[0] );
return this;
} else {
for ( var i = 0, l = insert.length; i < l; i++ ) {
var elems = (i > 0 ? this.clone(true) : this).get();
jQuery( insert[i] )[ original ]( elems );
ret = ret.concat( elems );
}
return this.pushStack( ret, name, insert.selector );
}
};
});
第5974行是本节的第一行:
if ( parent && parent.nodeType === 11 && parent.childNodes.length === 1 && insert.length === 1 ) {
insert[ original ]( this[0] );
return this;
}
答案 0 :(得分:0)