jQuery获取选择onChange的值 [英] jQuery get value of select onChange
本文介绍了jQuery获取选择onChange的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的印象是,我可以通过执行此 $(this).val();
并将 onchange
参数应用于选择字段.
I was under the impression that I could get the value of a select input by doing this $(this).val();
and applying the onchange
parameter to the select field.
它似乎只有在我引用 ID 时才有效.
It would appear it only works if I reference the ID.
我该如何使用它.
推荐答案
试试这个-
$('select').on('change', function() {
alert( this.value );
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select>
<option value="1">One</option>
<option value="2">Two</option>
</select>
你也可以通过 onchange 事件来引用-
You can also reference with onchange event-
function getval(sel)
{
alert(sel.value);
}
<select onchange="getval(this);">
<option value="1">One</option>
<option value="2">Two</option>
</select>
这篇关于jQuery获取选择onChange的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文