gpt4 book ai didi

jquery - 使用jquery自动将class更改为id

转载 作者:行者123 更新时间:2023-12-01 08:39:01 24 4
gpt4 key购买 nike

使用 jquery 可以自动将表中的类更改为 id。

作为此引导类的示例

<table class="table table-striped table-bordered">

到CSS ID

<table id="mytable">

我想使用我的打印页面的 ID

最佳答案

您只需使用类选择器选择该元素并添加 id属性如:

$('.table.table-striped.table-bordered').attr('id','mytable');

但是如果您还想删除这些类,

$('.table.table-striped.table-bordered').attr('id','mytable').removeAttr('class');

removeAttr('class')将从您的 class 中删除所有类(class)属性并使元素看起来像 <table id="mytable">来自<table class="table table-striped table-bordered">

关于jquery - 使用jquery自动将class更改为id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49812993/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com