如何使用 jQuery 統計表格中的列數
要使用 jQuery 統計表格中的列數,請使用 each() 函式和 attr()。你可以執行以下程式碼來了解如何統計表格中的列
示例
<html>
<head>
<title>jQuery Example</title>
<script src = "https://ajax.googleapis.com/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
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP