【发布时间】:2013-07-17 23:33:45
【问题描述】:
我有这个 HTML
<select id="something">
<option value="1" data-something="true">Something True</option>
<option value="2" data-something-else="false">Something Else False</option>
</select>
还有我试图从data-*属性中获取值的这个jQuery sn-p:
$(document).ready(function() {
$('body').on('change', 'select#something', function() {
console.log( $(this).data('something') ); // undefined always
console.log( $(this).data('something-else') ); // undefined always too
});
});
如何用jQuery获取data-*属性值?
【问题讨论】:
标签: javascript jquery html custom-data-attribute jquery-data