我正在尝试向下表中的属性添加下拉值。但是使用 jQuery 中的 .attr()
似乎不起作用
这是 jquery:
$("#datasize").change(function(){
var element = $(this).find('option:selected');
var myTag = element.val();
$('#filterTable1').attr('data-page-size' , myTag);
});
这是 html:
<select id="datasize">
<option value="10">My option</option>
<option value="20">My other option</option>
</select>
<table class="footable" data-page-size="" id="filterTable1">
<thead>
<tbody>
</tbody>
</thead>
</table>
如有任何帮助,我们将不胜感激!
最佳答案
$(function() {
$("#datasize").on('change', function(){
$('#filterTable1').attr('data-page-size' , this.value);
});
});
关于javascript - 将下拉列表中的值添加到 html 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16917184/