jQuery>;如何将选择列表的值传递给onclick处理程序?

jQuery>;如何将选择列表的值传递给onclick处理程序?,jquery,Jquery,下面有一个按钮元素,它有一个onclick处理程序。在onclick里面,我正在构建一个双元查询串。我需要使“template”变量动态以匹配“template”选择菜单中当前选定项的val()属性。我该怎么做 <select id="template">..select options</select> <button type="button" id="myButton" onclick="window.open('<?php echo $theP

下面有一个按钮元素,它有一个onclick处理程序。在onclick里面,我正在构建一个双元查询串。我需要使“template”变量动态以匹配“template”选择菜单中当前选定项的val()属性。我该怎么做

<select id="template">..select options</select>

<button 
type="button" 
id="myButton" 
onclick="window.open('<?php echo $thePath ?>/test.php?template=?????', 'popup'); 
return false;">
click me
</button>
。选择选项
$(“#我的按钮”)。单击(函数(){
var v=$('#template').prop('selected');//1.6版及更高版本中提供的prop
//或者您可以只使用$('#template').val();
onclick=“window.open('/test.php?template='+v',popup');
});
。选择选项
点击我
$(“#myButton”)。单击(函数(){
open('/test.php?template='+$('#template').val(),'popup');
返回false;
});
$("#myButton").click(function(){
var v = $('#template').prop('selected'); //prop available in version 1.6 and higher
// or you can just use $('#template').val(); 
onclick="window.open('<?php echo $thePath ?>/test.php?template='+v, 'popup'); 

});
<select id="template">..select options</select>
<button type="button" id="myButton">click me</button>
<script type="text/javascript">
    $('#myButton').click(function(){
        window.open('<?php echo $thePath ?>/test.php?template='+$('#template').val(), 'popup'); 
        return false;
    });
</script>