最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

JQuery實(shí)現(xiàn)動(dòng)態(tài)操作表格

 更新時(shí)間:2017年01月11日 13:25:35   作者:Yu2  
本文主要分享了jQuery實(shí)現(xiàn)對(duì)一個(gè)表格動(dòng)態(tài)的添加行,刪除行,并且對(duì)表格中內(nèi)容進(jìn)行非空驗(yàn)證的示例代碼。具有很好的參考價(jià)值,下面跟著小編一起來(lái)看下吧

最近要做的東西,是對(duì)一個(gè)表格動(dòng)態(tài)的添加行,刪除行,并且對(duì)表格中內(nèi)容進(jìn)行非空驗(yàn)證。

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script src="scripts/jquery-1.10.2.js"></script>
<script type="text/javascript">
$(function () {
//獲取表格的行數(shù)
var tabRowLen = $("table tbody tr").length;
//點(diǎn)擊add按鈕時(shí),
$("#add").on("click", function () {
//獲取表格的行數(shù)
tabRowLen = $("table tbody tr").length;
var index = tabRowLen - 1;
//表格行數(shù)為0時(shí),或者表格不存在空值時(shí)
if (IsNull(index) || tabRowLen == 0) {
//添加一行
$("table tbody").append("<tr>" +
"<td><input type='text' class='Name'/><div id='dName" + tabRowLen + "'></div></td>" +
"<td><input type='text' class='Age'/><div id='dAge" + tabRowLen + "'></div></td>" +
"<td><input type='button' class='add' value='delete ' /></td></tr>");
//刪除一行
$(".add").on("click", function () {
$(this).parents("tr").remove();
});
}
//keyup事件
$("table input").on("keyup", function () {
//驗(yàn)證是否有空值
IsNull(index);
});
});
function IsNull(trIndex) {
var result = true;
debugger;
//遍歷表格的input
$("table tbody input").each(function (trIndex) {
//判斷是否存在空值
if ($("table tbody input")[trIndex].value == "") {
//提示空值
result = false;
$(this).next().html("required");
}
//不為空
else {
//清空提示信息
$(this).next().html("");
}
});
return result;
};
});
</script>
</head>
<body>
<table>
<thead>
<tr>
<th>Name</th>
<th>Age</th>
<th><input type="button" id="add" value="addRow " /></th>
</tr>
</thead>
<tbody></tbody>
</table>
</body>
</html>

以上就是本文的全部?jī)?nèi)容,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來(lái)一定的幫助,同時(shí)也希望多多支持腳本之家!

相關(guān)文章

最新評(píng)論

西贡区| 南陵县| 关岭| 龙陵县| 金川县| 青浦区| 六枝特区| 平顶山市| 永昌县| 宁安市| 阳新县| 忻城县| 泾源县| 长子县| 芜湖县| 石渠县| 奎屯市| 呼图壁县| 库尔勒市| 黄浦区| 沭阳县| 游戏| 互助| 时尚| 陵水| 措勤县| 玉门市| 嘉义市| 墨玉县| 延长县| 新沂市| 棋牌| 绥化市| 正镶白旗| 长乐市| 平罗县| 祥云县| 洛扎县| 思南县| 遂昌县| 西盟|