jQuery获取选择后的值的方法

32 浏览
0 Comments

jQuery获取选择后的值的方法

我一直以为通过这样做 $(this).val(); 并将 onchange 参数应用于选择字段即可获得选择输入的值。

看起来它只有在引用ID时才起作用。

如何使用这个来做到。

admin 更改状态以发布 2023年5月22日
0
0 Comments

这对我很有帮助。

对于选择:

$('select_tags').on('change', function() {
    alert( $(this).find(":selected").val() );
});

对于单选/复选:

$('radio_tags').on('change', function() {
    alert( $(this).find(":checked").val() );
});

0
0 Comments

尝试一下这个 -

$('select').on('change', function() {
  alert( this.value );
});



你也可以应用 onchange 事件来引用 -

function getval(sel)
{
    alert(sel.value);
}


0