这是我的jsp:
<h1>Drop Down Menu</h1>
<div class="dropdown">
<select name="doctype" id="${rep}" class="my_dropdown" style="color:white; background:#655D78">
<option disabled="disabled" selected="selected">Select Doc Type</option>
这是我的jQuery函数:
<script type="text/javascript">
$(document).ready(function() {
var name = $("").val(); //value of the html id to be stored
alert($.name);
$.ajax({
url:'',
type:'post',
cache:false,
success: function(response){
}
});
});
</script>
我希望$ {rep}这个值在jQuery函数中。 有人可以帮帮我吗?
答案 0 :(得分:0)
要获取select id的值(在您的情况下: $ {rep} ),您可以按attribute value选择元素:
$('select[name="doctype"]')
var name = $('select[name="doctype"]').attr('id');
console.log('name: ' + name);
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<h1>Drop Down Menu</h1>
<div class="dropdown">
<select name="doctype" id="${rep}" class="my_dropdown" style="color:white; background:#655D78">
<option disabled="disabled" selected="selected">Select Doc Type</option>
</select>
</div>
&#13;