我有这个页面:
<html>
<head>
<body text="#000000" marginwidth="0" marginheight="0" bgcolor="#FFFFFF" onload="" topmargin="0" leftmargin="0">
<style type="text/css">
<table width="100%" cellspacing="0" cellpadding="0" align="center" style="page-break-after:always;">
<table width="100%" cellspacing="0" cellpadding="0" align="center" style="page-break-after:always;">
<table width="100%" cellspacing="0" cellpadding="0" align="center" style="page-break-after:always;">
<table width="100%" cellspacing="0" cellpadding="0" align="center" style="page-break-after:always;">
<table width="100%" cellspacing="0" cellpadding="0" align="center" style="page-break-after:always;">
<table width="100%" cellspacing="0" cellpadding="0" align="center" style="page-break-after:always;">
<table width="100%" cellspacing="0" cellpadding="0" align="center" style="page-break-after:always;">
<table width="100%" cellspacing="0" cellpadding="0" align="center" style="page-break-after:always;">
<table width="100%" cellspacing="0" cellpadding="0" align="center" style="page-break-after:always;">
<table width="100%" cellspacing="0" cellpadding="0" align="center" style="page-break-after:always;">
<table width="100%" cellspacing="0" cellpadding="0" align="center" style="page-break-after:always;">
<table width="100%" cellspacing="0" cellpadding="0" align="center" style="page-break-after:always;">
<table width="100%" cellspacing="0" cellpadding="0" align="center" style="page-break-after:always;">
<table width="100%" cellspacing="0" cellpadding="0" align="center">
</body>
</html>我需要向这些父表中的每一个添加唯一的ID。问题是,这些表中的每一个都有许多嵌套表。我只需要将I添加到所显示的每个I中。我该怎么做呢?我试过了:
jQuery("table").each(function(count){
var count = count + 1;
jQuery(this).attr("id","table"+count+"");
});但这会向所有表添加唯一的ID,即使是嵌套的表也是如此。任何帮助都将不胜感激。
发布于 2013-04-16 22:06:26
如果我理解正确的话,您可以简单地将父table元素(即那些body的直接后代)作为目标,如下所示:
$('body > table').each(function(i) {
$(this).prop('id', 'table'+(i + 1));
});发布于 2013-04-16 22:05:57
jQuery("body > table").each(function(count){
var count = count + 1;
jQuery(this).attr("id","table"+count+"");
});这将选择body的直接子项(表),我相信它应该对您有效
https://stackoverflow.com/questions/16039199
复制相似问题