English 中文(简体)
j Query AutoComplete, 如何接受“创始”术语
原标题:jQuery AutoComplete, How to accept Found & UnFound Terms

I m referencing the jQuery autocomplete plugin code seen in this tutorial: http://net.tutsplus.com/tutorials/javascript-ajax/how-to-use-the-jquery-ui-autocomplete-widget/

这一理论的问题是,它只支持服务器上发现的物品。 我想做的是,允许用户使用服务器上发现的物品(因为它今天运作),但也允许用户输入新的价值,而不冲破原始图...... 例如,你可以进入用户的电子邮件地址,进入媒体,然后继续使用假象,或许在服务器上找到另一个项目,再次打回。

想法? 可能吗?

最佳回答

你可以尝试评估建议清单中正在分类的内容。 这样,他们就能够基本上选择使用“req.term”的打字。 与此类似:

//process response
$.each(data, function(i, val){                              
    suggestions.push(val.name);
});
//append what has been typed in so it s available for selection
suggestions.push(req.term);
//pass array to callback
add(suggestions);

然后,在选择中:如果已经存在,你可以在数据库中加上“jax”电话。

//define select handler
select: function(e, ui) {

    //create formatted friend
    var friend = ui.item.value,
        span = $("<span>").text(friend),
        a = $("<a>").addClass("remove").attr({
            href: "javascript:",
            title: "Remove " + friend
        }).text("x").appendTo(span);

    //add friend to friend div
    span.insertBefore("#to");

    //insert selected email if doesn t already exists
},

在这里,在进入时插入您的模版朋友的一个关键例子:

$("#to").keypress(function(e){
    var code = (e.keyCode ? e.keyCode : e.which);
    if (code == 13) { //Enter keycode
        e.preventDefault();

        //create formatted friend
        var friend = $(this).val(),
            span = $("<span>").text(friend),
            a = $("<a>").addClass("remove").attr({
                href: "javascript:",
                title: "Remove " + friend
            }).text("x").appendTo(span);

        //add friend to friend div
        span.insertBefore("#to");

        $(this).autocomplete( close );
    }
});
问题回答

暂无回答




相关问题
getGridParam is not a function

The HTML: <a href="javascript:void(0)" id="m1">Get Selected id s</a> The Function: jQuery("#m1").click( function() { var s; s = jQuery("#list4").getGridParam( selarrrow )...

selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

jQuery cycle page with links

I am using the cycle plugin with pager functionality like this : $j( #homebox ) .cycle({ fx: fade , speed: fast , timeout: 9000, pager: #home-thumbs , ...

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

jConfirm with this existing code

I need help to use jConfirm with this existing code (php & Jquery & jAlert). function logout() { if (confirm("Do you really want to logout?")) window.location.href = "logout.php"; } ...

Wrap text after particular symbol with jQuery

What I m trying to do, is wrap text into div inside ll tag. It wouldn t be a problem, but I need to wrap text that appears particularly after "-" (minus) including "minus" itself. This is my html: &...

热门标签