2014-01-23 116 views
-1

在這裏有一個類似的問題關於這個問題,但我似乎無法得到它的工作。基於url中查詢字符串的選定下拉值

所以,當鏈接被點擊時,url會將該值傳遞給此頁面上的下拉列表,以便預填充。

<script type="text/javascript"> 
$(document).ready(function() { 
    $('#idOptions').on('change', function() { 
     window.location.assign('/string.html?strings=' + $(this).val()); 
    }); 
}); 
</script> 

<select id="idOptions"> 
     <option>option1</option> 
     <option>option2</option> 
     <option>option3</option> 
     <option>option4</option> 
     <option>option5</option> 
</select> 

然後下面的鏈接是在不同的頁面上。 ?

string.html串=選項

基於這個例子http://jsfiddle.net/73PEg/

回答

0

就這樣

上改變或點擊事件任何你需要

document.location.href = "http://someurl" + $("#idOptions").val(); 

window.location = "http://someurl" + $("#idOptions").val(); 
0

兩件事情:

  1. 您的代碼正在獲取選擇的值,當您需要選定的選項的值時。
  2. 你的選擇沒有價值,所以你必須得到選項的文字。

這裏有您需要的代碼:

$('#idOptions').on('change', function() { 
    window.location.assign('/string.html?strings=' + $(this).find('option:selected').text()); 
    // window.location.assign('/string.html?strings=' + $(this).find('option:selected').val()); // Use this one to get the option value instead of the text 
}); 

And a fiddle.

+0

選定'option's值或文本_is_的'select'的價值:http://jsfiddle.net/8z6B9/ –

+0

好ive現在爲選項標籤添加值並使用val() 是我的鏈接正確的即時通訊使用 string.html?strings = option2 – user2508199

相關問題