C#NET小弟我用jquery写的动态添加和删除,保存的时候不会写了。求大神解决,请在 btnSaveClick() 补充代码,万分感谢了
C#.NET我用jquery写的动态添加和删除,保存的时候不会写了。求大神解决,在线等。请在 btnSaveClick() 补充代码,万分感谢了。
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript" src="../Scripts/jquery-1.4.1.js"></script>
<script>
var arr = [];
$("#table1 tr td:nth-child(1)").each(function(key, value) {
arr.push($(this).html());
});
var result = arr.join(',');
//全选或全不选
//方法一:
//全选或全不选 此传入的参数为event 如:checkAll(event)
function checkAll(evt) {
$("#table1 tr").find("input[type='checkbox']").attr("checked", evt.checked);
}
//客户端动态添加行
function btnAddRow() {
//行号是从0开始,最后一行是新增、删除、保存按钮行 故减去2
var rownum = $("#table1 tr").length - 2;
var chk = "<input type='checkbox' id='chk_" + rownum + "' name='chk_" + rownum + "'/>";
//有点击事件的文本框
var text = "<input type='text' id='username_" + rownum + "' name='username_" + rownum + "' readonly='readonly' style='background-color: Gray' onclick='app("+rownum+")' width='75px'/>";
//无事件的文本框
var txt = "<input type='text' id='task_" + rownum + "' name='task_" + rownum + "' width='75px'/>";
var row = "<tr><td>" + chk + "</td><td>" + txt + "</td><td>" + text + "</td></tr>";
$(row).insertAfter($("#table1 tr:eq(" + rownum + ")"));
}
//这个比上面的要好,可以一下删除多个记录
function btnDeleteRow() {
$("#table1 tr").each(function(i) {
var chk = $(this).find("input[type='checkbox']");
if (chk.attr("id") != "checkall")//不能删除标题行
{
if (chk.attr("checked")) {
$(this).remove();
}
}
});
}
//客户端保存
function btnSaveClick() {
$("#table1 tr").find("td").each(function(i) {
if ($(this).find("input[type='text']").length > 0) {
alert($(this).find("input[type='text']").val());
}
});
}
function app(delbtn){
alert(delbtn);
window.open("choose.aspx","newwindow","height=600,width=500,toolbar=no,menubar=no,scrollbars=no,resizable=no, location=no,status=no");
var i = "wuxing;";
document.getElementById("username_"+delbtn).value = i;
}
</script>
</head>
<body>
<table id="table1" border="1" cellpadding="0" cellspacing="0">
<tr>
<th>
<input type="checkbox" id="checkall" onclick="checkAll(this)"/>
</th>
<th>项目名称</th>
<th>人员</th>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript" src="../Scripts/jquery-1.4.1.js"></script>
<script>
var arr = [];
$("#table1 tr td:nth-child(1)").each(function(key, value) {
arr.push($(this).html());
});
var result = arr.join(',');
//全选或全不选
//方法一:
//全选或全不选 此传入的参数为event 如:checkAll(event)
function checkAll(evt) {
$("#table1 tr").find("input[type='checkbox']").attr("checked", evt.checked);
}
//客户端动态添加行
function btnAddRow() {
//行号是从0开始,最后一行是新增、删除、保存按钮行 故减去2
var rownum = $("#table1 tr").length - 2;
var chk = "<input type='checkbox' id='chk_" + rownum + "' name='chk_" + rownum + "'/>";
//有点击事件的文本框
var text = "<input type='text' id='username_" + rownum + "' name='username_" + rownum + "' readonly='readonly' style='background-color: Gray' onclick='app("+rownum+")' width='75px'/>";
//无事件的文本框
var txt = "<input type='text' id='task_" + rownum + "' name='task_" + rownum + "' width='75px'/>";
var row = "<tr><td>" + chk + "</td><td>" + txt + "</td><td>" + text + "</td></tr>";
$(row).insertAfter($("#table1 tr:eq(" + rownum + ")"));
}
//这个比上面的要好,可以一下删除多个记录
function btnDeleteRow() {
$("#table1 tr").each(function(i) {
var chk = $(this).find("input[type='checkbox']");
if (chk.attr("id") != "checkall")//不能删除标题行
{
if (chk.attr("checked")) {
$(this).remove();
}
}
});
}
//客户端保存
function btnSaveClick() {
$("#table1 tr").find("td").each(function(i) {
if ($(this).find("input[type='text']").length > 0) {
alert($(this).find("input[type='text']").val());
}
});
}
function app(delbtn){
alert(delbtn);
window.open("choose.aspx","newwindow","height=600,width=500,toolbar=no,menubar=no,scrollbars=no,resizable=no, location=no,status=no");
var i = "wuxing;";
document.getElementById("username_"+delbtn).value = i;
}
</script>
</head>
<body>
<table id="table1" border="1" cellpadding="0" cellspacing="0">
<tr>
<th>
<input type="checkbox" id="checkall" onclick="checkAll(this)"/>
</th>
<th>项目名称</th>
<th>人员</th>