[英]How To Detect Option Change When Using selectBoxIt JQuery Plugin?
$(".abc123").selectBoxIt();
$(document).on('mousedown', function(e) {
if ($(e.target).parent().parent().parent().parent().children(":first").hasClass('abc123')) {
var anchor = $(this).find('a');
var test = $(anchor).text();
alert($(this).parent().attr('class'));
}
})
The above is a snippet of my much larger script where I am trying to apply additional functions mousedown section. 以上是我更大的脚本的片段,我正在尝试应用其他功能mousedown部分。 I'm using the selectBoxIt JQuery plugin which will turn any basic select option list into a more prettier version.
我正在使用selectBoxIt JQuery插件,它会将任何基本选择选项列表转换为更漂亮的版本。
Even though you're using a plugin to style the select
, you can still hook to the change
event of the underlying element, like this: 即使你使用插件来设置
select
样式,你仍然可以挂钩底层元素的change
事件,如下所示:
$(".abc123").selectBoxIt().change(function() {
console.log(this.value);
});
I'm not certain exactly what your current code is attempting to do as this
is the document
and therefore attempting to get the parent()
is moot, however the above code will at least get you the current value of the select when it's changed. 我不确定你当前的代码究竟在尝试做什么,因为
this
是document
,因此尝试获取parent()
是没有意义的,但是上面的代码至少会在选择更改时获得select的当前值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.