[英]Yii2: select2 with jQuery event doesn't work
I am trying to trigger a function when a value of a Select2 is selected. 我正在尝试选择Select2的值时触发一个函数。 The select2 has name of colors. select2具有颜色名称。
$('#idColor').on('select2:selecting', function(e) {
console.log($('#idColor').val());
});
Example: I select the option Blue and nothing happened. 示例:我选择了“蓝色”选项,但没有任何反应。 Then I select the color Red and the console shows Blue. 然后选择红色,控制台显示蓝色。
The Select2 widget is in a Yii2 project created by another person. Select2小部件位于另一个人创建的Yii2项目中。 So I couldn't find its documentation web. 所以我找不到它的文档网站。
Maybe I have a similar problem to this, but this person use Backbone.js: Click and Change event not working for jquery-select2 options 也许我有与此类似的问题,但是此人使用Backbone.js: Click and Change事件不适用于jquery-select2选项
I am learning jQuery, so maybe I am doing something wrong. 我正在学习jQuery,所以也许我做错了。
Could be you are not using the right event Try using onChange 可能是您未使用正确的事件尝试使用onChange
$('#idColor').on('change', function(e) {
console.log($('#idColor').val());
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.