gpt4 book ai didi

jQuery - 添加 ID 而不是类

转载 作者:IT王子 更新时间:2023-10-29 03:25:35 25 4
gpt4 key购买 nike

我正在使用当前的 jQuery :

$(function() {
$('span .breadcrumb').each(function(){
$('#nav').addClass($(this).text());
$('#container').addClass($(this).text());
$('.stretch_footer').addClass($(this).text())
$('#footer').addClass($(this).text());
});
});

它将面包屑中的文本应用到页面上的 4 个元素,让我可以专门针对页面上的样式设置样式。

我想尝试添加一个 ID 而不是一个类,我该如何实现?

最佳答案

试试这个:

$('element').attr('id', 'value');

这样就变成了;

$(function() {
$('span .breadcrumb').each(function(){
$('#nav').attr('id', $(this).text());
$('#container').attr('id', $(this).text());
$('.stretch_footer').attr('id', $(this).text())
$('#footer').attr('id', $(this).text());
});
});

因此,您正在更改/覆盖三个元素的 id,并为一个元素添加一个 id。您可以根据需要进行修改...

关于jQuery - 添加 ID 而不是类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2176986/

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