js和Jquery获取选中select值和文本
Posted on 2012-12-11 16:46 shenyixin 阅读(15368) 评论(0) 编辑 收藏JS:
<body>
<select name="PaymentType" style="110px" >
<option value="">请选择 </option>
<option value="001">月付</option>
<option value="002">半年付</option>
<option value="003">年付</option>
</select>
<script language="javascript">
function Gettext(obj){
var txt=obj.options[obj.options.selectedIndex].text;
alert(txt)
}
function Getvaule(obj){
var val=obj.options[obj.options.selectedIndex].value;
alert(val)
}
</script>
</body>
Jquery:
<body>
<select name="PaymentType" style="110px" >
<option value="">请选择 </option>
<option value="001">月付</option>
<option value="002">半年付</option>
<option value="003">年付</option>
</select>
<script language="javascript">
function Gettext(obj){
var txt=$(obj).find("option:selected").text();
alert(txt)
}
function Getvaule(obj){
var val=$(obj).find("option:selected").val();
alert(val)
}
</script>
</body>