2010-10-18 64 views
0

再次卡住了,並要求你幫助我。如何傳遞搜索字符串以執行搜索?

我想在輸入字段中輸入搜索字符串。搜索字符串應該執行類似https://.../=~searchstring

文本字段搜索:

$("<input id='field-inputSearchString' type='text' name='field_inputSearchString'>").insertAfter('.completed ticket');

我來到這裏的兩個問題:

  1. 我想我需要「找」字符串傳遞它到搜索鏈接。是嗎?喜歡這個?

    $(function() { 
    var foundin = $('input[id$='field-inputSearchString']:contains(text)'); 
    }); 
    

  2. And how do I pass the text to the link? Have you got an example or link explaining what I'm looking for?

I appreciate every help. Thank you so much in advance.

+0

你試圖做一個簡單的形式,還是必須是AJAX的href? – 2010-10-18 08:19:30

+0

它應該儘可能簡單。 – Chookie 2010-10-18 08:24:36

+1

所以當它應該很簡單時,爲什麼不使用表單?您可以將提交按鈕設置爲超鏈接,因此無需使用javascript解決方法。 – 2010-10-18 08:29:42

回答

0

To get the value of an input field with id you can do

$("#field-inputSearchString").val(); 

You cannot use :contains,因爲它搜索包含文本的元素。

如果你想將字符串傳遞給一個錨定標記

var href = $("#anchorID").attr("href"); 
$("#anchorID").attr("href", href + $("#field-inputSearchString").val()); 
+0

這是一個很好的提示。 TY。 – Chookie 2010-10-18 08:17:13