繁体   English   中英

使用selectBoxIt JQuery插件时如何检测选项更改?

[英]How To Detect Option Change When Using selectBoxIt JQuery Plugin?

JSBin现场演示

  $(".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'));
    }
  })

以上是我更大的脚本的片段,我正在尝试应用其他功能mousedown部分。 我正在使用selectBoxIt JQuery插件,它会将任何基本选择选项列表转换为更漂亮的版本。

检测新选项更改的最佳解决方案是什么?

即使你使用插件来设置select样式,你仍然可以挂钩底层元素的change事件,如下所示:

$(".abc123").selectBoxIt().change(function() {
    console.log(this.value);
});

我不确定你当前的代码究竟在尝试做什么,因为thisdocument ,因此尝试获取parent()是没有意义的,但是上面的代码至少会在选择更改时获得select的当前值。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM