javascript - jquery库和mootoos库同时使用问题,闭包出现报错了
高洛峰
高洛峰 2017-04-10 14:45:16
[JavaScript讨论组]

网页中同时导入2种js库,并且加上了 var jquery = $.noConflict(true);但是页面中报错了

<p 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></p>

chrome控制台报错了: Uncaught TypeError: undefined is not a function说的是($('searchbar_3949')); 这个闭包调用函数

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

全部回复(1)
天蓬老师

你获取id是不是少了个#号?

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号