如何添加属性';id';到JavaScript或jquery中的类?
我有一张带id的桌子和一个班级。我正在使用一个插件来修复前两列和标题,以满足我的要求。我的表格由标记定义:如何添加属性';id';到JavaScript或jquery中的类?,javascript,jquery,Javascript,Jquery,我有一张带id的桌子和一个班级。我正在使用一个插件来修复前两列和标题,以满足我的要求。我的表格由标记定义: <table class="fancyTable" id="myTable03" cellpadding="0" cellspacing="0"> 我想在此表中添加其他功能。在通过firebug检查DOM之后,我发现这个表被插件分成了两部分(我想是这样的)。当桌子的一部分变成 <table class="fht-table fancyTable" style="ma
<table class="fancyTable" id="myTable03" cellpadding="0" cellspacing="0">
我想在此表中添加其他功能。在通过firebug检查DOM之后,我发现这个表被插件分成了两部分(我想是这样的)。当桌子的一部分变成
<table class="fht-table fancyTable" style="margin-top: 0px;">
<table id="myTable03" class="fancyTable fht-table fht-table-init" cellspacing="0" cellpadding="0" style="width: 926px; margin-top: -40px;">
另一个变成了
<table class="fht-table fancyTable" style="margin-top: 0px;">
<table id="myTable03" class="fancyTable fht-table fht-table-init" cellspacing="0" cellpadding="0" style="width: 926px; margin-top: -40px;">
我想将属性id添加到包含类“fht table FANYTABLE”的表中。我该怎么做?我正在使用Jquery/javascript。来自第二个,您已经有了id
myTable03
如果要将属性id
添加到包含类fht表fancyTable
那就试试这个,
$(".fht-table.fancyTable:not('#myTable03')").attr('id','myTable04');
从你已经有id的第二张表中阅读 如果要将
属性id
添加到包含类fht表fancyTable
那就试试这个,
$(".fht-table.fancyTable:not('#myTable03')").attr('id','myTable04');
阅读你需要这样的东西:
$('.fht-table.fancyTable').not('#myTable03').prop('id', 'yourId');
或
您将需要以下内容:
$('.fht-table.fancyTable').not('#myTable03').prop('id', 'yourId');
或
属性ID可以添加为属性的常规属性。但对该元素的引用不应通过Id获取 您可以使用:
$("div").attr("id", "div1");
注意:两个元素不能具有相同的id
var divs = document.getElementsByTagName('div');
或
var divs=document.getElementsByClassName('fancyTable');
for(var i=0;i属性ID可以作为属性的正常属性添加。但不应通过ID获取对该元素的引用
您可以使用:
$("div").attr("id", "div1");
注意:两个元素不能具有相同的id
var divs = document.getElementsByTagName('div');
或
var divs=document.getElementsByClassName('fancyTable');
对于(var i=0;i请发布您迄今为止尝试过的内容。jQuery文档中有一个关于DOM操作的部分,您可能希望先看一看:。如果您不知道如何选择正确的元素,请查看。请发布您迄今为止尝试过的内容。jQuery文档中有一个关于DOM操作的部分,您可能希望首先看一看:。如果您不知道如何选择正确的元素,请看一看。您肯定会给我提示。$(“.fht table.fancyTable”).attr(“id”,“myTable”);$(.fht table.fancyTable.fht table init”).attr(“id”,“myTable03”);我现在得到了答案。您肯定会给我提示。$(“.fht table.fancyTable”).attr”(.id”,“myTable”)。attr(“id”,“myTable”)$(“.fht table.fancyTable.fht table init”).attr(“id”,“myTable03”);我现在得到了答案。