jquery库和mootoos库同时使用问题,闭包出现报错了
网页中同时导入2种js库,并且加上了
var jquery = $.noConflict(true);
但是页面中报错了
<div style="float: right; padding-right: 12px;" class="headerseach">
<form async="false" id="searchbar_3949" method="post"
action="http://www.bbready.com/search-result.html"><a
id="asubmit" href="javascript:void(0);"><img
src="http://img.bbready.com/themes/yibeite/818pro/images/seach.gif"></a>
<input type="text" autocomplete="off" data-autocompleter="" value=""
name="search_keywords" id="search_keywords"/></form>
<script>
(function(scope) {
scope.getElementById('asubmit').addEvent('click', function(e) {
if (scope.getElement('input').value.trim() === '') {
e.stop();
} else {
document.getElementById('searchbar_3949').submit();
}
});
var search_keywords = decodeURIComponent(Memory.get('search_key'));
if (search_keywords == 'null') {
search_keywords = '';
}
//scope.getElement('input[name=search_keywords]').value = search_keywords;
})($('searchbar_3949'));
jquery("#search_keywords").autocomplete({
minChars: 1,
url: 'index.php?c=Search&a=getKeyWords',
sortFunction: function(a, b, filter) {
var f = filter.toLowerCase();
var fl = f.length;
var a1 = a.value.toLowerCase().substring(0, fl) == f ? '0' : '1';
var a1 = a1 + String(a.data[0]).toLowerCase();
var b1 = b.value.toLowerCase().substring(0, fl) == f ? '0' : '1';
var b1 = b1 + String(b.data[0]).toLowerCase();
if (a1 > b1) {
return 1;
}
if (a1 < b1) {
return -1;
}
return 0;
},
showResult: function(value, data) {
return '<span style="color:red">' + value + '</span>';
},
onItemSelect: function(item) {
var text = 'You selected <b>' + item.value + '</b>';
if (item.data.length) {
text += ' <i>' + item.data.join(', ') + '</i>';
}
jquery("#last_selected").html(text);
},
mustMatch: true,
maxItemsToShow: 5,
selectFirst: false,
autoFill: false,
selectOnly: true,
remoteDataType: 'json'
});
</script></div>
chrome控制台报错了:
Uncaught TypeError: undefined is not a function
说的是
($('searchbar_3949'));
这个闭包调用函数
jquery web前端开发 程序员 html5 JavaScript
zxcvb
10 years, 1 month ago