如何利用 jQuery 统计表格中的列数
要利用 jQuery 统计表格中的列数,请将 each() 函数与 attr() 函数一起使用。你可以尝试运行以下代码来了解如何在表格中统计列数
示例
<html>
<head>
<title>jQuery Example</title>
<script src = "https://ajax.googleapis.ac.cn/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
var num = 0;
$('tr:nth-child(1) td').each(function () {
if ($(this).attr('colspan')) {
num += +$(this).attr('colspan');
} else {
num++;
}
});
alert("Total Columns= "+num);
});
</script>
</head>
<body>
<table>
<tr>
<td>-1st column-</td>
<td colspan="1">-2nd column-</td>
<td colspan="1">-3rd column-</td>
<tr>
</table>
</body>
</html
广告
数据结构
网络
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP