<select>
<option>1</option>
<option>2</option>
<option>3</option>
</select>
往往需要获取这个选择值,怎么办呢?
<script>
$("select").change(function(){
alert( $("option.selected").text() )
})
</script>
参考网址
http://api.jquery.com/change/
By anthor way. 今天在第二次写地址信息的时候,发现了另外一种获取select 值得方法
$("select").val()
你可以在控制台打印一下,就会发现真的Ok。
还有一行关于清除select信息的
$("select").each(function (index,val) {
$(this).val($(this).children(":first").text());
})
$(this).children(":first").text()
这个是获取第一个子元素的文本信息
也可以用别的方法,比如
$(this).children().first().val();
$(this).children().eq(0).val();
等等方法
有时候考虑问题的思路不要重复以前的套路,也许会发现一条更加简便的方法。即使没有找到比原来更加好的,那么你思考的过程,也是成长的过程
关于select 操作的方法,点击这里看参考信息