gpt4 book ai didi

javascript - 自动完成功能无法按照 fiddle 运行

转载 作者:行者123 更新时间:2023-12-03 09:25:13 24 4
gpt4 key购买 nike

我只想完全像这个 fiddle 一样:http://fiddle.jshell.net/dryydaxq/show/light/

但是我收到错误消息:

Uncaught ReferenceError: jQuery is not defined(anonymous function) @ jquery-ui.min.js:6(anonymous function) @ jquery-ui.min.js:6 multi-auto.js:13

Uncaught ReferenceError: $ is not defined

我确实引用了有关该主题的一些讨论,并确保在插件之前包含 jquery 库。然后该库显示为包含在 Chrome 开发工具的源代码下。

有人能发现我犯的错误吗?
HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link rel="stylesheet" type="text/css" href="jquery-ui.css" />
<script src="jquery-ui.min.js"></script>
<script src="multi-auto.js"></script>

</head>

<body>
<div style="margin:10px 10px;padding:8px;width:90%;" class="ui-widget ui-widget-content ui-corner-all">
<div style="margin:0 0 6px 2px;">Type in a color</div>

<!-- This input control gets turned into the jquery ui widget -->
<input id="search" type="text" style="padding:4px;font-size:.8em;width:95%;"/>
</div>

<div id="outputDiv" style="margin:10px">Select a color and the value will display here</div>



</body>
</html>

jQuery

/*
* jQuery UI Multicolumn Autocomplete Widget Plugin 2.2
* Copyright (c) 2012-2015 Mark Harmon
*
* Depends:
* - jQuery UI Autocomplete widget
*
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*/
$.widget('custom.mcautocomplete', $.ui.autocomplete, {
_create: function() {
this._super();
this.widget().menu( "option", "items", "> :not(.ui-widget-header)" );
},
_renderMenu: function(ul, items) {
var self = this, thead;

if (this.options.showHeader) {
table=$('<div class="ui-widget-header" style="width:100%"></div>');
// Column headers
$.each(this.options.columns, function(index, item) {
table.append('<span style="float:left;min-width:' + item.minWidth + ';">' + item.name + '</span>');
});
table.append('<div style="clear: both;"></div>');
ul.append(table);
}
// List items
$.each(items, function(index, item) {
self._renderItem(ul, item);
});
},
_renderItem: function(ul, item) {
var t = '',
result = '';

$.each(this.options.columns, function(index, column) {
t += '<span style="float:left;min-width:' + column.minWidth + ';">' + item[column.valueField ? column.valueField : index] + '</span>'
});

result = $('<li></li>')
.data('ui-autocomplete-item', item)
.append('<a class="mcacAnchor">' + t + '<div style="clear: both;"></div></a>')
.appendTo(ul);
return result;
}
});


var columns = [{
name: 'Color',
minWidth: '100px'},
{
name: 'Hex',
minWidth: '70px'}],
colors = [['White', '#fff'], ['Black', '#000'], ['Red', '#f00'], ['Green', '#0f0'], ['Blue', '#00f']];

$("#search").mcautocomplete({
showHeader: true,
columns: columns,
source: colors,
select: function(event, ui) {
// Set the input box's value
this.value = (ui.item ? ui.item[0] : '');
// Set the output div's value
$('#outputDiv') && $('#outputDiv').text(ui.item ? ('You have selected ' + ui.item[1]) : 'Select a color');
return false;
}
});

最佳答案

您还没有包含 jQuery。添加

<script src="//code.jquery.com/jquery-1.11.3.min.js"></script>

到页面的头部(在 jQuery UI 之前)。

关于javascript - 自动完成功能无法按照 fiddle 运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31700819/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com