2014-01-23 30 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

相关问题