我有一个选择元素,它由 Select2 通过 SonataAdminBundle 装饰。
我正在尝试监听更改事件。我的选择标签的 ID 是“categorySelector”。
这不起作用:
var test = $('#categorySelector');
$(test).change(function() {
var theSelection = $(test).select2("val");
//$('#selectedID').text(theID);
console.log(theSelection);
});
我该怎么做?
最佳答案
我认为这应该适合你......
$('#categorySelector').on("change", function(e) {
var theSelection = e.val();
console.log(theSelection);
});
关于javascript - 如何绑定(bind)到 select2 更改事件并获取所选值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21906307/