【问题标题】:jQuery add border to tablejQuery为表格添加边框
【发布时间】:2010-04-28 11:05:36
【问题描述】:

我是 jQuery 新手,我试过这个:

<input value="1"  type="checkbox" name="mytable" id="checkbox2"  style="float:left;"
        />

{literal}

<script src="http://code.jquery.com/jquery-latest.js"></script>
            <script type="text/javascript">
$(function() {
   //checkbox
   $(".mytable").click(function(){
    $(".mytable").toggleClass('mytableborders');

    });
});
</script>
{/literal}

<table class="mytable" id="cart">....</table>

但这不起作用,我要复选框将表的类从.mytable更改为.mytableborders

【问题讨论】:

    标签: jquery html css checkbox html-table


    【解决方案1】:

    您的复选框 ID 是“checkbox2”。所以你的复选框的选择器是$("#checkbox2"),你的表ID是“cart”,选择器是$("#cart")

    试试

    $("#checkbox2").click(function(){
        $("#cart").toggleClass('mytableborders');
    });
    

    【讨论】:

      【解决方案2】:
      $(function() {
        $("#checkbox2").click(function(){
          $("#cart").toggleClass('mytableborders');
        });
      });
      

      点击事件应该通过ID而不是名称附加到复选框。

      【讨论】:

        【解决方案3】:

        Toggle 类将在该类不存在时添加该类,如果存在则将其删除。如果您希望它交换类,请使用addClassremoveClass

            $(".mytable").removeClass('mytable').addClass('mytableborders');
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2014-01-19
          • 2013-02-26
          • 1970-01-01
          • 1970-01-01
          • 2021-12-31
          • 1970-01-01
          • 2018-12-27
          • 2018-01-14
          相关资源
          最近更新 更多