td内部元素td的php-id
php id of element td inside of td
我有那个表,我想通过php或JS在td的所有元素中获取td的ID。
你能帮我吗?
<table id="czytelnicy">
<tr>
<td class="kolumna pogrubienie">I</td>
<td class="kolumna pogrubienie" id="B_1_1">B_1_1</td>
<td class="kolumna" id="B_1_2">B_1_2</td>
<td class="kolumna" id="B_1_3">B_1_3</td>
<td class="kolumna" id="B_1_4">B_1_4</td>
<td class="kolumna" id="B_1_5">B_1_5</td>
<td class="kolumna" id="B_1_6">B_1_6</td>
<td class="kolumna" id="B_1_7">B_1_7</td>
<td class="kolumna" id="B_1_8">B_1_8</td>
<td class="kolumna pogrubienie" id="B_1_9">B_1_9</td>
<td class="kolumna" id="B_1_10">B_1_10</td>
<td class="kolumna" id="B_1_11">B_1_11</td>
<td class="kolumna pogrubienie" id="B_1_12">B_1_12</td>
<td class="kolumna" id="B_1_13">B_1_13</td>
</tr>
</table>
使用JQUERY
var index = 1;
$("table#czytelnicy tr td").each(function(){
$(this).attr('id', 'B_1_'+index+'');
index++;
});
使用纯JavaScript
var ids = document.getElementsByTagName('td');
var id_arr = [];
for(var i = 0; i<ids.length; i++) {
id_arr.push(ids[i].id);
}
console.log(id_arr);
输出
["", "B_1_1", "B_1_2", "B_1_3", "B_1_4", "B_1_5", "B_1_6", "B_1_7", "B_1_8", "B_1_9", "B_1_10", "B_1_11", "B_1_12", "B_1_13"]
Fiddle here
使用JQuery。你可以把每个id放在一个数组中。
var idArray = [];
$("table#czytelnicy tr td").each(function(){
idArray.push($(this).attr("id"));
});
return idArray
工作Fiddle
你可以退货,也可以为所欲为。希望我能帮上忙。
$('.kolumna').each(function(){
alert($(this).attr('id'));
});
//这给出了该类下的所有id
相关文章:
- 正在获取生成的PHP td值
- tu如何将id放在填充了json数据的html表td上
- 从Bootstrap获取活动选项卡ID并将其传递给PHP
- PHP会话ID变量与AJAX一起返回
- Php,Javascript-动态表单id's和动态验证
- 在具有多个值的 PHP 函数中传递 ID
- 将 JavaScript 元素 ID 传递给 PHP 或 Form Variable
- 将图像附加到没有 id 或值的 td 元素
- 在 PHP 生成的表中添加和访问按钮 ID
- 当 td id 已知时,在 jquery 中设置 td 背景颜色
- 从 PHP 获取当前页面 ID 后调用 jQuery 事件
- JqSuite PHP:获取列名或id
- 正在获取td的id
- AJAX 删除表中选择了 PHP ID 的行
- Rails3jQuery:如何提醒td的id
- td内部元素td的php-id
- 如何调用td's id来更改CSS样式
- 在JavaScript函数中为td指定ID
- AJAX 停止加载同一站点不同的 PHP ID
- 如何在Jquery可排序后更新多个td的Id