jQuery中的onchange事件 [英] onchange event in jquery
本文介绍了jQuery中的onchange事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在select字段中的jquery中实现 onchange 事件,因为jquery不会产生跨浏览器的兼容性问题.我的脚本代码是
I am trying to implement onchange event in jquery on select field,as jquery does not create cross browsers compatibility problems. My scripting code is
<script>
$('#payment_method').change(function () {
if ($('#payment_method').val() == 'check') {
alert('hello');
}
});
</script>
这是选择字段的代码
<select id="payment_method" name="country" class="form-control" >
<option value="">Select One</option>
<option value="check">Check</option>
<option value="bank_transfer">Bank/Wire Transfer</option>
<option value="paypal">Paypal</option>
<option value="smart_card">Smart Money Card</option>
</select>
但是当我选择检查选项时什么也没发生
but nothing is happening when I select check option
推荐答案
文档准备就绪后,您需要 ready事件来运行代码.
You need ready event to run your code when document is ready.
<script>
$(document).ready(function(){
$('#payment_method').change(function () {
if ($(this).val() == 'check') {
alert('hello');
}
});
});
</script>
这篇关于jQuery中的onchange事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文