简体   繁体   English

在jQuery selectmenu之后捕获data-attribute

[英]catch data-attribute after jQuery selectmenu

I am unable to catch the data-attribute after the applying jQuery UI select menu on it. 在应用jQuery UI选择菜单后,我无法捕获data-attribute。

How is it possible to get the data? 如何获取数据?

HTML: HTML:

<select class="drpmnu">

         <option data-timings="something1">(01)</option>

         <option data-timings="something2">(02)</option>

</select>

JavaScript: JavaScript的:

 $(".drpmnu").selectmenu({
    change: function( event, ui ){
        console.log($(this).data('timings'));
    }
});

http://jsbin.com/hicura/1/edit?html,console,output http://jsbin.com/hicura/1/edit?html,console,output

this refers to the selectmenu itself, not the object in it. this指的是selectmenu本身,而不是其中的对象。 You need to use ui.item for that: 您需要使用ui.item

$(".drpmnu").selectmenu({
    change: function( event, ui ){
        console.log($(ui.item.element).data('timings'));
    }
});

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

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