无法从元素中删除属性

时间:2020-04-24 08:18:16

标签: jquery

我的html如下所示: 根据其他功能显示第一个<tr>

        <tr style="display: none;">
            <td class="label_column">
            </td>
            <td class="data_column" width="auto">
                <input class="proper_gsc_indexing" type="checkbox" data-toggle="toggle" data-on="jest poprawne" data-off="nie jest poprawne" data-size="small"
                           data-onstyle="success" data-offstyle="danger" name="proper_gsc_indexing" checked="checked" data-width="200">
            </td>
        </tr>

        <tr class="proper_gsc_indexing_list" style="display: none;">
            <td class="label_column">
                Linki
            </td>
            <td width="auto">
                <textarea class="form-control" rows="3" name="proper_gsc_indexing_list" style="max-width: 75%"></textarea>
            </td>
        </tr>

我尝试根据按钮<tr>的状态从.proper_gsc_indexing_list .proper_gsc_indexing删除样式属性:

            if( data.boolean_data.proper_gsc_indexing == true){
                $('[name="proper_gsc_indexing"]').prop('checked', true).change();
            } else {
                $('[name="proper_gsc_indexing"]').prop('checked', false).change();
                console.log('inside');
                $(".proper_gsc_indexing_list").show();
                $(".proper_gsc_indexing_list").css("display", "");
                $(".proper_gsc_indexing_list").removeAttr("style");
            }

按钮值的当前状态为false,控制台返回我在代码的其他部分内,但是删除样式的尝试均无效。

加载页面后控制台显示<tr>元素仍包含style="display: none;"

谢谢您的建议。

1 个答案:

答案 0 :(得分:0)

解决方案是使用toggle()代替show()

$(".proper_gsc_indexing_list").toggle('slow');