国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

超級簡單的jquery操作表格方法

2024-05-06 16:12:06
字體:
供稿:網(wǎng)友
這篇文章主要介紹了超級簡單的jquery操作表格方法,可實(shí)現(xiàn)針對表格行與列的增加及刪除操作,是非常實(shí)用的技巧,需要的朋友可以參考下
 
 

本文實(shí)例講述了超級簡單的jquery操作表格方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:

利用jquery給指定的table添加一行、刪除一行

復(fù)制代碼代碼如下:
<script language="javascript" src="./jquery.js"></script>
<table border="1px #ooo" id="test" name="test" class="test" cellpadding="0" cellspacing="0" width="20%">
<tr id="1"><td width="30%">1</td>
<td width="30%">2</td>
<td width="30%">3</td></tr>
<tr id="2"><td width="30%">11</td>
<td width="30%">22</td>
<td width="30%">33</td></tr>
</table>
<table border="1px #ooo" id="test1" name="test1" cellpadding="0" cellspacing="0" width="20%"> <tr id="4"><td width="30%">1</td>
<td width="30%">2</td>
<td width="30%">3</td>
</tr>
</table>
<input type="button" name="button" value="add" onclick="addtr('test');">
<input type="button" name="button" value="del" onclick="deltr('test');">
<script> //在id為test的table的最后增加一行
function addtr(id){ tr_id = $("#test>tbody>tr:last").attr("id");
tr_id++; //alert(tr_id);
str = "<tr id = '"+tr_id+"'><td width='30%'>re1</td><td width='30%'>re2</td><td width='30%'>re3</td></tr>";
$('#'+id).append(str); } //刪除id為test的table的最后一行
function deltr(id){ tr_id = $("#test>tbody>tr:last").attr("id"); $('#'+tr_id).remove();
}
</script>

 
jQuery動態(tài)添加刪除表格的行和列 
復(fù)制代碼代碼如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<style type="text/css"> .cl1{ background-color:#FFFFFF; } .cl2{ background-color:#FFFF99; } </style>
<script type="text/javascript" src="css_js/jquery/jquery-1.3.2.min.js"></script>
<script type="text/javascript">
var rowCount = 0;
var colCount = 2;  
function addRow(){ rowCount++; var rowTemplate = '<tr class="tr_'+rowCount+'"><td>'+rowCount+'</td><td class="cl1">內(nèi)容'+rowCount+'</td><td class="cl1"><a href="#" onclick=delRow('+rowCount+')>刪除</a></td></tr>';
var tableHtml = $("#testTable tbody").html();
tableHtml += rowTemplate; $("#testTable tbody").html(tableHtml); }
  function delRow(_id){ $("#testTable .tr_"+_id).hide(); rowCount--; }  
function addCol(){ colCount++; $("#testTable tr").each(function(){  
var trHtml = $(this).html(); trHtml += '<td onclick="delCol('+colCount+')">增加的td</td>';
$(this).html(trHtml);
});  
}  
function delCol(_id){   $("#testTable tr").each(function(){ $("td:eq("+_id+")",this).hide(); });
colCount--;
}  
function mover(_id){ $("#testTable tr:not(:first)").each(function(){ $("td:eq("+_id+")",this).removeClass("cl1");
$("td:eq("+_id+")",this).addClass("cl2"); }); }  
function mout(_id){ $("#testTable tr:not(:first)").each(function(){ $("td:eq("+_id+")",this).removeClass("cl2");
$("td:eq("+_id+")",this).addClass("cl1"); }); } </script>
<title>jquery操作表格測試</title>
</head>
<body>
<table id="testTable" border="1" width="500"> <tr>
<td>序號</td> <td onmouseover="mover(1);" onmouseout="mout(1);">內(nèi)容</td>
<td onmouseover="mover(2);" onmouseout="mout(2);">操作</td> </tr>
</table>
<input type="button" value="添加行" onclick="addRow();"/>
<input type="button" value="添加列" onclick="addCol();"/>
</body>

 

jquery操作表格(添加/刪除行、添加/刪除列)

復(fù)制代碼代碼如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<script type="text/javascript" src="jquery-1.4.4.min.js"></script>
<title>jquery操作表格測試</title>
<script type="text/javascript">
function del(_id){ $("#testTable .tr_"+_id).html('');
var tableTr = $("#testTable .tr_"+_id).hide(); }
function addRow(){ var addRowTemplete = '<tr class="tr_'+tableCount+'">
<td class="cl1">'+tableCount+'</td><td class="cl1">內(nèi)容'+tableCount+'</td>
<td class="cl1"><a href="javascript:void(0)" onclick=del('+tableCount+');>刪除</a></td></tr>'; $("#testTable tbody").append(addRowTemplete); } function addCol(){ $("#testTable tr").each(function(){    var trHtml = "<td onclick='delCol("+colCount+")'>曾加的td</td>";    $(this).append(trHtml); }); } function delCol(_id){ $("#testTable tr").each(function(){    $("td:eq("+_id+")",this).hide(); }); }
</script> </head>
<body>
<table width="487" border="1" id="testTable"> <tr> <td onclick="delCol(0)">序號</td> <td onclick="delCol(1)">內(nèi)容</td> <td onclick="delCol(2)">操作</td> </tr> </table> <p> <input type="button" name="Submit" value="添加行" onclick="addRow()" /> <input type="button" name="Submit2" value="添加列" onclick="addCol()"/> </p> </body>
</html>

復(fù)制代碼代碼如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>我的百分之一女裝店官方網(wǎng)站|白菜園社區(qū)|4000-921001|就愛百分一</title>
<meta name="keywords" content="我的百分之一,我的百分之一女裝店,我的百分之一商城,我的百分之一淘寶" />
<meta name="description" content="我的百分之一淘寶三金冠女裝店官方網(wǎng)站100f1.com,僅為百分一有品位的美女!我的百分之一商城每月發(fā)布新款時(shí)尚女裝和潮流服飾女裝搭配。" />
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script>
</head>
<body>
<div id="wrap" class="wrap">
<div class="fatie" id="fatie">
<dl class="options">
<dd>選項(xiàng)<span>1</span>:<input type="text"  class="text"  /><a class="base_icon" href="javascript:void(0);">刪除</a></dd>
<dd>選項(xiàng)<span>2</span>:<input type="text"  class="text"  /><a class="base_icon" href="javascript:void(0);">刪除</a></dd>
<dd>選項(xiàng)<span>3</span>:<input type="text"  class="text"  /><a class="base_icon" href="javascript:void(0);">刪除</a></dd>
<dd>選項(xiàng)<span>4</span>:<input type="text"  class="text"  /><a class="base_icon" href="javascript:void(0);">刪除</a></dd>
<dd>選項(xiàng)<span>5</span>:<input type="text"  class="text"  /><a class="base_icon" href="javascript:void(0);">刪除</a></dd>
</dl>
<p class="add_opt">
<span class="base_icon">添加更多選項(xiàng)</span>
</p>
</div>
</div>
</body>
<script type="text/javascript">
$(document).ready(function(){//投票選項(xiàng)增減控制
var fatie = $("#fatie");
var option = fatie.find(".options dd");
function list_again(){//選項(xiàng)重新排序
option.each(function(){
var i = $(this).index();
$(this).find("span").html(i+1);
})
}
fatie.find(".add_opt span").click(function(){//增加選項(xiàng)
fatie.find(".options").append('<dd>選項(xiàng)<span>i</span>:<input type="text"  class="text"  /><a class="base_icon" href="javascript:void(0);">刪除</a></dd>');
option = fatie.find(".options dd");
list_again();
})
option.find("a").live("click",function(){//刪除選項(xiàng)
$(this).parent().remove();
list_again();
})
})
</script>
</html>

 

希望本文所述對大家的jquery程序設(shè)計(jì)有所幫助。


發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表

圖片精選

主站蜘蛛池模板: 马鞍山市| 大洼县| 车致| 广水市| 南宫市| 旌德县| 高尔夫| 五华县| 宁强县| 获嘉县| 伊通| 南丹县| 同江市| 临桂县| 乌审旗| 大渡口区| 太谷县| 萨迦县| 诏安县| 金溪县| 莱芜市| 义马市| 凤山县| 三门县| 彰武县| 兴隆县| 武夷山市| 石城县| 大化| 咸丰县| 晴隆县| 莱西市| 渭源县| 邵阳县| 德江县| 霍城县| 敦煌市| 富源县| 吴川市| 嵊泗县| 元朗区|