更改事件不适用于多个选择输入 [英] Change event not working on multiple select input

查看:98
本文介绍了更改事件不适用于多个选择输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的更改事件不会在多重选择输入上触发。每当多重选择的值发生变化时,我想要激发一个事件。

HTML:

 < select style ='width:361px;'multiple =multipleclass ='multiselect-status'> 
< option>待定< / option>
< option>已批准< / option>
< option>扣除< / option>
< option>未批准< / option>
< / select>

JS:

('change','select.multiselect-status',函数(e){

console.log($) $(this).val());

});

任何想法为什么没有解雇?谢谢!


$ b

编辑:通过jquery的load()函数加载HTML,如果它有所不同的话。 $ b

解决方案

在dom就绪或加载html时绑定更改事件 -



<$ p $功能(){
$(body)。on('change','select.multiselect-status',function(e){
console。 log($(this).val());
});
});



 <$ ('change',function(e){($'$'$'$''''')。 
console.log($(this).val());
});
});


My change event is not firing on a multiple select input. I would like an event to fire each time the multiple select's value is changed.

HTML:

<select style='width: 361px;' multiple="multiple" class='multiselect-status'>
  <option>Pending</option>
  <option>Approved</option>
  <option>Deducted</option>
  <option>Not Approved</option>
</select>

JS:

$("body").on('change', 'select.multiselect-status', function(e){

  console.log($(this).val());

});

Any ideas why this isn't firing? Thanks!

EDIT: The HTML is being loaded via jquery's load() function, if it make's a difference.

解决方案

Bind change event either on dom ready or while you are loading your html -

$(function(){
  $("body").on('change', 'select.multiselect-status', function(e){
    console.log($(this).val());
  });
});

Or

$('#something').load('something.html',function(){
  $("select.multiselect-status").on('change', function(e){
    console.log($(this).val());
  });
});

这篇关于更改事件不适用于多个选择输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆