我需要获得SELECT标签的当前值.为此,我正在使用$('select').val(),但这只返回默认值,并且不会更改.可能我可以帮帮我吗?
$('div#buy input').fancybox({
ajax : {
type : "POST",
data : {
id: $('input[name="id"]').val(),
count: $('#count').val()
}
}
});
<select id="count">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>
Run Code Online (Sandbox Code Playgroud)
$('#count').val()将返回当前选定的值.你缺少选项的价值.
<select id="count">
<option value="1">1</option>
<option value="2">2</option>........
Run Code Online (Sandbox Code Playgroud)
编辑:
如果您不想在选项中指定值,则可以使用.
$('#count :selected').val()
Run Code Online (Sandbox Code Playgroud)