I have a button element below that has an onclick handler. Inside the onclick I'm building a dyanamic querystring. I need to make the "template" variable dynamic to match the val() property of the currently selected item in the "template" select menu. How can I do this?
<select id="template">..select options</select>
<button
type="button"
id="myButton"
onclick="window.open('<?php echo $the开发者_运维技巧Path ?>/test.php?template=?????', 'popup');
return false;">
click me
</button>
I know I can grab the selected option in jQuery with $('#template :selected').val();
How can I pass this to the onclick handler?
<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>
$("#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');
});
精彩评论