jquery autocomplete组合框错误:未捕获类型错误:Object[Object Object]没有方法
jquery autocomplete combobox error: Uncaught TypeError: Object [object Object] has no method 'button'
我正在尝试使用jquery ui插件实现一个自动完成组合框
使用下面提到的代码,我能够实现自动完成部分,但不能实现下拉部分(由于未捕获的类型错误,下拉箭头不可见)
$.widget( "ui.combobox", {
_create: function() {
var input,
self = this,
select = this.element.hide(),
selected = select.children( ":selected" ),
value = selected.val() ? selected.text() : "",
wrapper = this.wrapper = $( "<span>" )
.addClass( "ui-combobox" )
.insertAfter( select );
input = $( "<input>" )
.appendTo( wrapper )
.val( value )
.addClass( "ui-state-default ui-combobox-input" )
.autocomplete({
delay: 0,
minLength: 0,
source: function( request, response ) {
var matcher = new RegExp( $.ui.autocomplete.escapeRegex(request.term), "i" );
response( select.children( "option" ).map(function() {
var text = $( this ).text();
if ( this.value && ( !request.term || matcher.test(text) ) )
return {
label: text.replace(
new RegExp(
"(?![^&;]+;)(?!<[^<>]*)(" +
$.ui.autocomplete.escapeRegex(request.term) +
")(?![^<>]*>)(?![^&;]+;)", "gi"
), "<strong>$1</strong>" ),
value: text,
option: this
};
}) );
},
select: function( event, ui ) {
ui.item.option.selected = true;
self._trigger( "selected", event, {
item: ui.item.option
});
},
change: function( event, ui ) {
if ( !ui.item ) {
var matcher = new RegExp( "^" + $.ui.autocomplete.escapeRegex( $(this).val() ) + "$", "i" ),
valid = false;
select.children( "option" ).each(function() {
if ( $( this ).text().match( matcher ) ) {
this.selected = valid = true;
return false;
}
});
if ( !valid ) {
// remove invalid value, as it didn't match anything
$( this ).val( "" );
select.val( "" );
input.data( "autocomplete" ).term = "";
return false;
}
}
}
})
.addClass( "ui-widget ui-widget-content ui-corner-left" );
input.data( "autocomplete" )._renderItem = function( ul, item ) {
return $( "<li></li>" )
.data( "item.autocomplete", item )
.append( "<a>" + item.label + "</a>" )
.appendTo( ul );
};
$( "<a>" )
.attr( "tabIndex", -1 )
.attr( "title", "Show All Items" )
.appendTo( wrapper )
.button({
icons: {
primary: "ui-icon-triangle-1-s"
},
text: false
})
.removeClass( "ui-corner-all" )
.addClass( "ui-corner-right ui-combobox-toggle" )
.click(function() {
// close if already visible
if ( input.autocomplete( "widget" ).is( ":visible" ) ) {
input.autocomplete( "close" );
return;
}
// work around a bug (likely same cause as #5265)
$( this ).blur();
// pass empty string as value to search for, displaying all results
input.autocomplete( "search", "" );
input.focus();
});
},
destroy: function() {
this.wrapper.remove();
this.element.show();
$.Widget.prototype.destroy.call( this );
}
});
$( "#combobox" ).combobox();
以上代码在document.ready下。由于".button"方法而引发错误
html:
<tr>
<td><label>Country:</label></td>
<td>
<div class="ui-widget">
<select id="combobox">
<option value="">Select one...</option>
<option value="ActionScript">ActionScript</option>
<option value="AppleScript">AppleScript</option>
<option value="Asp">Asp</option>
<option value="BASIC">BASIC</option>
<option value="C">C</option>
</select>
</div>
</td>
</tr>
组合框css,
.ui-combobox {
position: relative;
display: inline-block;
}
.ui-combobox-toggle {
position: absolute;
top: 0;
bottom: 0;
margin-left: -1px;
padding: 0;
/* adjust styles for IE 6/7 */
*height: 1.7em;
*top: 0.1em;
}
.ui-combobox-input {
margin: 0;
padding: 0.3em;
}
脚本序列为,
<script type="text/javascript" src="<?php echo base_url('/assets/js/jquery.js'); ?>"></script>
<script type="text/javascript" src="<?php echo base_url('/assets/js/validation.js'); ?>"></script>
<script type="text/javascript" src="<?php echo base_url('/assets/autocomplete/js/jquery-ui-1.8.21.custom.min.js'); ?>"></script>
<?= $_scripts ?>
- jquery版本1.7.2,jquery ui版本1.8.21
- 我试着重新安排剧本的顺序
- 不存在不同jquery版本的多个实例
如有任何帮助,我们将不胜感激。谢谢
您的代码看起来不错,所以问题几乎可以肯定是您的自定义jQuery UI构建中没有包含ui.button
。
您可以通过运行typeof $.ui.button
来验证这一点。如果您包含了它,它将是function
,如果您不包含,它将为undefined
。
重新构建jQuery UI,并确保选中Button
复选框。
相关文章:
- object响应时出现对象错误javascript
- 如何访问npm模块抛出的自定义错误对象[error:[object object]]
- 运行咕噜咕噜咕噜抛出 _.object 不是函数错误
- jqxGrid失败并出现错误“;Object[Object Object]没有方法'jqGrid'&”;
- onclick=“;doSomething([object object])“;未捕获的语法错误:意外的标识符
- Object.defineProperty获取集返回错误的值
- 未捕获的类型错误:Object[Object Object]没有方法'fancybox'
- Javascript错误Object函数没有方法'url'
- jQuery令牌输入轨道获取错误Uncaught TypeError:Object[Object Object]没有方法
- Array.insert函数错误,因为Object函数Array(){〔本机代码〕}没有方法'插入'
- 附加字符串时,for循环中出现Javascript[Object-Object]错误
- 未捕获的类型错误:属性'$'对象[object Window]的
- 未捕获的类型错误:Object[Object Object]没有方法'滑块'
- 未捕获的类型错误:Object[Object global]没有方法'generateCards'
- 如何避免在object.keys中不存在obj时发生错误
- jquery autocomplete组合框错误:未捕获类型错误:Object[Object Object]没有方法
- 获取 [Object HTMLInputElement] 错误
- Google Chrome Object.defineProperty中的错误行为
- 发生错误:[object object]错误
- AngularJS $locationProvider.search()会导致Uncaught Object错误