簡體   English   中英

調用Jquery自動完成ajax函數

[英]Call Jquery Autocomplete ajax function

我有一個jQuery自動完成ajax函數,其源代碼是從后面的代碼計算得出的。 但是我使用客戶端腳本管理器在javascript中獲取源代碼,但我的函數沒有執行。

除此之外,我試圖從后面的代碼中調用該ajax函數。

ClientScriptManager.RegisterStartupScript()

但是我的功能再次沒有執行。 我的功能是:

<form id="form1" runat="server">
    <div>
        <input id="Text1" type="text"/>&nbsp;&nbsp;&nbsp;
        <input id="Text2" type="text" /><br />
        <br />
        <input id="Button2" type="button" value="button" />

    <script type="text/javascript">
    var mydataformat = [{ label: "....", value: "....", icon: "....." }, 
                        { label: "....", value: ".....", icon: "....." }];

    $(function() {
    $("#Text1").autocomplete({                      
    minLength: 0,                      
    source: JSVar,                      
    focus: function (event, ui) 
    {
    $("#Text1").val(ui.item.label);                          
    return false;                      
    }})                     
    .data("autocomplete")._renderItem = function (ul, item) {                         
    return $("<li></li>") 
    .data("item.autocomplete", item)                             
    .append("<a><img src='" + item.icon + "' width='32' height='32' />  " + item.label + "</a>")                             
    .appendTo(ul);                     
        }; 
    });

</script>

你必須設置源時,你的數據已經加載喜歡提到這里

$("#Text1").autocomplete( "option", "source", ["your", "loaded", "data"] );

...或者更好地在計算出的數據准備就緒時初始化自動完成,而不是更早。

看一下jQueryUI網站上的Custom Data示例 ,它似乎涵蓋了你想要的一切。 它使用標簽,價值,圖標等。

唯一剩下的部分是等到數據加載完畢后再進行初始化。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM