Re: [問題] 請問如何在php表格中 利用javascript新 …
※ 引述《savin (小馬克)》之銘言:
: 請問一下
: 可以在PHP的表格中 用Java指令來讓表格多出一行嗎?
PHP 沒有表格 Javascript
: 大概是這樣
: 簡單的說 就是按下新增表格的按鍵 就能多一行
: 有哪個函數適合?
: 我想這可能是很簡單的問題
: 新手上路 請多包含
: PS 我剛跑到Java被人指點來這邊
這邊用最簡單的複製最後一列作範例
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"" rel="nofollow">http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="" rel="nofollow">http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>js</title>
</head>
<body>
<input id="copyLastRow" type="button" />
<table>
<tbody id="results">
<tr>
<td>第1列第1欄</td>
<td>第1列第2欄</td>
<td>第1列第3欄</td>
</tr>
<tr>
<td>第2列第1欄</td>
<td>第2列第2欄</td>
<td>第2列第3欄</td>
</tr>
</tbody>
</table>
<script type="text/javascript">
(function(){
var get = function(id) {
return document.getElementById(id);
}
var tbody = get('results');
var btn = get('copyLastRow');
btn.onclick = function(){
// 擷取所有 tr
var trs = tbody.getElementsByTagName('tr');
// 擷取最後一個 tr
var trLast = trs[trs.length - 1];
// 複製這個 tr
var trClone = trLast.cloneNode(true);
// 把複製出來的 tr 插入 tbody 尾端
tbody.appendChild(trClone);
}
})();
</script>
</body>
</html>
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 114.40.216.36
推
02/17 07:19, , 1F
02/17 07:19, 1F
Ajax 近期熱門文章
PTT數位生活區 即時熱門文章