佳木斯湛栽影视文化发展公司

主頁 > 知識庫 > 巧妙使用JQuery Clone 添加多行數(shù)據(jù),并更新到數(shù)據(jù)庫的實現(xiàn)代碼

巧妙使用JQuery Clone 添加多行數(shù)據(jù),并更新到數(shù)據(jù)庫的實現(xiàn)代碼

熱門標簽:電子圍欄 服務(wù)器配置 Mysql連接數(shù)設(shè)置 Linux服務(wù)器 科大訊飛語音識別系統(tǒng) 團購網(wǎng)站 銀行業(yè)務(wù) 阿里云
web前端代碼:
復制代碼 代碼如下:

%@ Page Language="C#" AutoEventWireup="true" CodeFile="BatchAdd.aspx.cs" Inherits="BatchAdd" %>
!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 runat="server">
title>/title>
/head>
body>
form id="form1" runat="server" action="BatchAdd.aspx">
div>
table id="tblData">
tr>
td>
ID
/td>
td>
Title
/td>
td>
SmallClassName
/td>
td>
Author
/td>
td>
UpdateTime
/td>
/tr>
tr id="tRow0">
td>
input type="text" id="txtID" name="txtID0" />
/td>
td>
input type="text" id="txtTitle" name="txtTitle0" />
/td>
td>
input type="text" id="txtSmallClassName" name="txtSmallClassName0" />
/td>
td>
input type="text" id="txtAuthor" name="txtAuthor0" />
/td>
td>
input type="text" id="txtUpdateTime" name="txtUpdateTime0" />
/td>
/tr>
/table>
input type="hidden" id="hidNum" name="hidNum" value="0" />
input type="button" id="btnAdd" value="Add" />
input type="submit" id="btnSave" value="Save" />
/div>
/form>
/body>
/html>
script src="js/jquery-1.4.2.min.js" type="text/javascript">/script>
script language="javascript" type="text/javascript">
$(function() {
$("#btnAdd").click(function() {
var num = $("#hidNum").val(); //
num = parseInt(num);
num++; //點擊自加
$("#hidNum").val(num); //重新賦值
$("#tRow0").clone(true).attr("id", "tRow" + num).appendTo("#tblData"); //clone tr 并重新給定ID,裝到table
$("#tRow" + num + " td").each(function() {//循環(huán)克隆的新行里面的td
$(this).find("input[type='text']").val(""); //清空克隆行的數(shù)據(jù)
//修改相關(guān)屬性
$(this).find("input[name='txtID0']").attr("id", "txtID" + num).attr("name", "txtID" + num);
$(this).find("input[name='txtTitle0']").attr("id", "txtTitle" + num).attr("name", "txtTitle" + num);
$(this).find("input[name='txtSmallClassName0']").attr("id", "txtSmallClassName" + num).attr("name", "txtSmallClassName" + num);
$(this).find("input[name='txtAuthor0']").attr("id", "txtAuthor" + num).attr("name", "txtAuthor" + num);
$(this).find("input[name='txtUpdateTime0']").attr("id", "txtUpdateTime" + num).attr("name", "txtUpdateTime" + num);
});
});
});
/script>

cs頁面代碼:
復制代碼 代碼如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class BatchAdd : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(Request["hidNum"]))
{
int num = Convert.ToInt32(Request["hidNum"]);
string id, title, smallClassName, author, updatetime;
int rs = 0;
if (num > 0)
{
for (int i = 0; i = num; i++)
{
id = Request["txtID" + i];
title = Request["txtTitle" + i];
smallClassName = Request["txtSmallClassName" + i];
author = Request["txtAuthor" + i];
updatetime = Request["txtUpdateTime" + i];
string sql = "insert into News(Title,SmallClassName,Author,Updatetime) values('" + title + "','" + smallClassName + "','" + author + "','" + updatetime + "')";
DBHelper.connString = "server=.;database=test;uid=sa;pwd=123";
if (DBHelper.ExecuteSql(sql) > 0)
rs++;
}
Response.Redirect("Manager.aspx?rs=" + rs);
}
}
}
}
您可能感興趣的文章:
  • jQuery復制節(jié)點用法示例(clone方法)
  • JQuery中clone方法復制節(jié)點
  • jQuery中clone()方法用法實例
  • jquery的clone方法應用于textarea和select的bug修復
  • jQuery Clone Bug解決代碼
  • jQuery中clone()函數(shù)實現(xiàn)表單中增加和減少輸入項

標簽:江蘇 衡水 衢州 萍鄉(xiāng) 廣元 蚌埠 棗莊 大理

巨人網(wǎng)絡(luò)通訊聲明:本文標題《巧妙使用JQuery Clone 添加多行數(shù)據(jù),并更新到數(shù)據(jù)庫的實現(xiàn)代碼》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266
    义乌市| 昌邑市| 保定市| 项城市| 衡阳市| 郸城县| 昌乐县| 平和县| 科尔| 揭阳市| 华容县| 博野县| 正安县| 建阳市| 道孚县| 方山县| 岱山县| 中江县| 双柏县| 高邑县| 临洮县| 霍林郭勒市| 红原县| 同心县| 乾安县| 高要市| 百色市| 定日县| 东兰县| 南丹县| 师宗县| 清镇市| 夏邑县| 株洲市| 兖州市| 青龙| 慈利县| 凤冈县| 竹北市| 河曲县| 方城县|