2013-02-07 30 views
0

我正在使用Jquery令牌輸入自動搜索字段。 我需要動態發送PropertyToSearch字段值。Jquery令牌輸入 - 動態傳遞propertyToSearch屬性值

HTML:

<input checked="checked" name="suggest" type="radio" />Month 
    <input name="suggest" type="radio" />Day</label> 

如在上述HTML字段。

當我選擇月份時,列表應該被列爲月份並且 當我選擇日期時,列表應該列爲週日。

現在我路過propertyToSearch默認像下面,

SCRIPT:

  $("#demo").tokenInput(../Management/getDaysAndMonths, 
      { 
       propertyToSearch: "Month", 
       tokenLimit: 1 
      }); 

我是如何動態地設置propertyToSearch字段值。以便它可以根據所選的單選按鈕字段切換列出的值。

請通過建議澄清我。

在此先感謝。

回答

0

我有一個解決方案。

而不是改變propertyToSearch。我只是簡單地改變了後面的代碼,以便根據提供的輸入列出值。

因此,如果選擇月份。我傳遞一個參數「searchProperty」在網址爲個月如果日已被選定我傳遞一個參數爲天基礎上,searchProperty值。我列出這些值並將其傳遞到下拉列表中。

 $("#demo").tokenInput("../Management/getDaysAndMonths?searchProperty="+$('input[name="suggest"]').val(), 
     { 
      //code 
     }); 
0

使用jQuery selecot RTO選擇值...

$('input[name="suggest"]').val() 
    -^^^^^^^^^^^^^^^^^^^^^^--selects input with name=suggest and .val() selects the selected radio value. 

試試這個

HTML

<input checked="checked" name="suggest" type="radio" value="Month"/>Month 
<input name="suggest" type="radio" value="Day"/>Day</label> 

JQUERY

$("#demo").tokenInput(../Management/getDaysAndMonths, 
    { 
    propertyToSearch:$('input[name="suggest"]').val(), 
    tokenLimit: 1 
    }); 
+0

不,它不能正常工作。當我們選擇另一個單選按鈕時,propertyToSearch值不會改變。它仍然是第一個選中的值 – logarajaks