如何处理Jquery自定义功能未定义的场景?

时间:2019-07-02 14:17:04

标签: javascript jquery

我在jquery中定义了一个自定义功能,如下所示

 jQuery.predictiveTextInit = function (obj, options) {
    //do something 
}

我正在像下面这样称呼功能

<script>
     $(document).ready(function () {
        assignselectedvalues();
    })
    function getpredictions_c(e, selector, loc) {
        localStorage['SearchCache'] = "";
        $(".myInputContainer2").hide();
        var hdnPredictiveval = $('#hdnPredictiveURL').val();
        var formatselector = "." + selector;
        var formatloc = "." + loc; //".searchCommunityLocation";//"." + loc;
        var ptObj = { url: hdnPredictiveval, suggestContainer: formatselector };
        $.predictiveTextInit($(formatloc), ptObj);
        $(".searchCommunityLocation").val(e.target.value);
    }
</script>

html

 <input type="text" class="@searchCommunityLocation" onkeyup="getpredictions_c(event,'@dynamicContainer','@searchCommunityLocation')" name="searchCommunityLocation" id="searchCommunityLocation"/>

但是有时我会收到错误消息,例如$ .predictiveTextInit不是一个函数,但有时效果很好,这可能是什么原因?

提前感谢

0 个答案:

没有答案