2011-12-14 60 views
3

我想知道有人能夠幫我處理我的查詢嗎?Jquery UI自動完成 - 選擇結果到DIV而不是表單域

我有以下代碼很好,但我想發佈其中一個選定的結果到一個DIV而不是一個表單字段。

我已經嘗試過101件事情,但解決方案超越了我。

我還以爲製作表單域及隱藏的內容複製到支持JavaScript的DIV將是一個解決方案,直到我意識到,我不知道該怎麼做,要麼...

$("#search").catcomplete({ 
     delay: 0, 
     source: 'complete_client.php', 
     minLength: 2, 
     select: function(event, ui) { 
      $("#id").val(ui.item.id); 
      $("#title").val(ui.item.value); 
      $("#spec").val(ui.item.spec); 
      document.forms["main_search"].submit(); 
    } 
    }); 

我會在可能的情況下像ID一樣保留在表單字段中,標題和規範將填充DIV。

如果它不可能/太多的工作,會自動將表單內容複製到一個DIV使用Javascript可能/更容易嗎?

提前感謝

克里斯

回答

1
$("#search").catcomplete({ 
    delay: 0, 
    source: 'complete_client.php', 
    minLength: 2, 
    select: function(event, ui) { 
     // Put selected item's text into div 
     $('#divid').text(ui.item.value); 

     /* Whatever other code you want here */ 
} 
}); 
+0

感謝馬修,但我想,纔沒有對我不起作用。最初我希望它會變得如此簡單 - 還有什麼進一步的建議?謝謝克里斯 – Chris 2011-12-14 00:59:14