简体   繁体   English

为什么 jQuery 模糊无法使用 jQuery 的 tag-it 库?

[英]Why is the jQuery blur not working jQuery's tag-it library?

I am trying to use JQuery's blur with tag-it library, however, it isn't working.我正在尝试将 JQuery 的模糊与 tag-it 库一起使用,但是它不起作用。

I am not sure why blur isn't working.我不确定为什么模糊不起作用。

I click off the input and nothing happens, I don't get an error.我点击输入,没有任何反应,我没有收到错误。

The alert in the blur doesn't appear.模糊中的警报不会出现。

I have tried using:我试过使用:

.on(blur, handler) 

And:和:

$(document).ready(function(){
    ("#id").blur()
})

Neither of them worked.他们都没有工作。

Here is my code:这是我的代码:

var id_name = [[],[]];
var selected = true;
$("#Approversdisp").tagit({
    allowSpaces: true,
    autocomplete:{
        minLength: 3,
        delay: 600,
        source: function(request, response){
            $("#divreviewersearch").show();
            $.ajax({
                "url" :"private",
                "type" : "GET",
                "data" : {"name": request.term.trim()},
                "contentType" : "application/json",
                "success" : function(data) {
                    id_name[0] = data[0];
                    id_name[1] = data[1];
                    response(data[0]);
                    $("#divreviewersearch").hide();
                },
                "error" : function(error)
                {
                    alert("error: "+JSON.stringify("There was an error!"));
                }
            });
        },
        select: function(event, ui) {
            selected = false;
            var nameid = ui.item.value;
            var approvers = document.addcontent' . $item_id .'.Approvers.value;
            ui.item.label = ui.item.label.replace(/\((.*?)\)/, "");
            ui.item.value = ui.item.value.replace(/\((.*?)\)/, "");
            document.addcontent' . $item_id .'.Approvers.value = approvers+"|"+id_name[1][id_name[0].indexOf(nameid)];
        },
    }
});
$("#Approversdisp").blur(function() {
    alert("in blur");
    if(selected){
        var input = $("#Approversdisp").val();
        input = input.split(",");
        $("#Approversdisp").tagit("removeTagByLabel", input[input.length-1]);
        alert("please pick the tag from the list.");
    }
    selected = true;

});

The expected result is the blur working.预期的结果是模糊工作。

I figured out the answer you have to use我想出了你必须使用的答案

$("#inputid").data("ui-tagit").tagInput.blur()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM