【问题标题】:Add value from dropdown to html attribute将下拉列表中的值添加到 html 属性
【发布时间】:2013-05-30 19:27:26
【问题描述】:

我正在尝试将下拉值添加到下表中的属性。但是使用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>

任何帮助将不胜感激!

【问题讨论】:

  • 它已经工作了 - jsfiddle.net/jxXsN
  • 它确实有效...这是一个有冲突的库 :) 谢谢

标签: javascript jquery html html-table html-select


【解决方案1】:
$(function() {
    $("#datasize").on('change', function(){ 
        $('#filterTable1').attr('data-page-size' , this.value); 
    });
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-04-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-12
    • 1970-01-01
    相关资源
    最近更新 更多