<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeBehind="TestForDemo.aspx.cs" Inherits="Maticsoft.Web.Product.TestForDemo" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<script src="../js/checkBoxHelper.js"></script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<input type="button" id="btn_Update" value="批量更新" />
<span>全部选择:<input type="checkbox" name="SelectAll" /></span>
<table class="table">
<thead>
<th>选择</th>
<th>产品Id</th>
<th>名称</th>
<th>描述</th>
<th>生产厂家</th>
<th>价格</th>
<th>链接</th>
<th>标题 </th>
</thead>
<%=ConsTr %> </table>
<script type="text/javascript">
$(document).ready(function () {
$("input[name='SelectAll']").click(function () {
if ($(this).attr("checked") == "checked") {
checkBoxHelper.allChecked();
}
else {
checkBoxHelper.allCancle(); }
});
$("input[name='forTest']").click(function () {
if ($(this).attr("checked") == "checked") { checkBoxHelper.addTr(this);
}
else {
var $tr = $(this).parents("tr");
$tr.next(".newrow").remove(); }
});
$("#btn_Update").click(function () {
if ($(this).val() == "批量更新") {
var check = checkBoxHelper.getChecked();
if (check.length == 0) {
alert("至少选择一个");
return false;
}
$(this).val("保存");
$.each(check, function (index, element) {
checkBoxHelper.addTr(element);
}); }
else {
$(this).val("批量更新");
alert("保存成功");
} });
}); </script>
</asp:Content>

HTML

 var checkBoxHelper = {
///全选
allChecked: function () {
$('input[name="forTest"]').attr("checked", "checked");
},
allCancle: function () {
$("input[name='forTest']").each(function () {
this.checked = !this.checked;
});
},
getChecked: function () {
var check = new Array();
$("input[name='forTest']").each(function () {
if (this.checked) {
check.push(this);
}
}); return check;
},
addTr: function (element) {
var $tr = $(element).parents("tr");
if ($tr.next(".newrow").length>0) {
return false;
}
if ($("#btn_Update").val() == "批量更新") {
return false;
}
var price = $tr.find("#price").text();
var select = "<select>";
select += "<option>请选择</option>";
select += "<option>ywx236602</option>";
var $td = "<td>" + select + price + "</td>";
var aftertr = $("<tr class='newrow'></tr>");
aftertr.append($td);
$tr.after(aftertr);
} };

JS

 using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Maticsoft.Model;
using System.Text; namespace Maticsoft.Web.Product
{
public partial class TestForDemo : System.Web.UI.Page
{
public string ConsTr { get; set; }
protected void Page_Load(object sender, EventArgs e)
{
List<Products> prods = new BLL.Products().GetModelList("");
StringBuilder sb = new StringBuilder();
sb.Append("<tbody>");
foreach (var item in prods)
{
sb.Append("<tr>");
sb.AppendFormat("<td><input type='checkbox' name='forTest' id='{0}'/></td>",item.ProductId);
sb.AppendFormat("<td>{0}</td>", item.ProductId);
sb.AppendFormat("<td>{0}</td>",item.Name);
sb.AppendFormat("<td>{0}</td>",item.Description);
sb.AppendFormat("<td>{0}</td>",item.Catagory);
sb.AppendFormat("<td id='price'>{0}</td>",item.Price);
sb.AppendFormat("<td>{0}</td>",item.Href);
sb.AppendFormat("<td>{0}</td>",item.Title);
sb.Append("</tr>"); }
sb.Append("</tbody>");
ConsTr=sb.ToString();
}
}
}

c#

动态根据checkbox 增加Dom的更多相关文章

  1. ExtJs 3.0 动态生成 CheckBox

    在开发过程中,往往需要利用数据动态生成Checkbox.如权限节点.考试答案,调查选项等等.在Extjs中,有两种方法来获取后台数据,一是Ext.Ajax()方法,第二种是利用 Store,store ...

  2. 代码动态创建checkbox

    根据数据库的内容动态创建Checkbox控件并显示在Panel上 dataset ds=new dataset(); CheckBox[ ] cb=new CheckBox[ds.tables[0]. ...

  3. Jquery动态操作checkbox

    问题的由来:html页面中使用checkbox给新建用户授权,然后提交到后台服务器,完成给用户授权.用户授权完成之后,如果用户的权限发生改变管理员需要修改多个用户的权限或查看某用户的权限,点击不同的用 ...

  4. ng-checked选择和点击增加dom

      1.需求 在添加页面实现一个checkbox的选择,然后在详情页面展示时,会自动选上之前被选中的. 2.添加页面 看官最好将这个代码复制过去看看效果. <!DOCTYPE html>& ...

  5. C语言基础 - 实现动态数组并增加内存管理

    用C语言实现一个动态数组,并对外暴露出对数组的增.删.改.查函数 (可以存储任意类型的元素并实现内存管理) 这里我的编译器就是xcode 分析: 模拟存放 一个 People类 有2个属性 字符串类型 ...

  6. layui动态设置checkbox选中状态

    今天在使用jquery动态设置layui的checkbox元素的选中状态时始终只能取消选中,却不能重新勾选,点击勾选则没有问题,代码如下 if (value == "true") ...

  7. VUE 动态给对象增加属性,并触发视图更新。

    在开发过程中,我们时常会遇到这样一种情况:当vue的data里边声明或者已经赋值过的对象或者数组(数组里边的值是对象)时,向对象中添加新的属性,如果更新此属性的值,是不会更新视图的. 根据官方文档定义 ...

  8. 动态生成CheckBox(Winform程序)

    在做用户权限设置功能时,需要做一个动态生成权限列表的功能.(笔记.分享) //1.清空权限控件组的默认控件 panelPermissions.Controls.Clear(); _groupBoxLi ...

  9. hadoop节点动态删除与增加

    动态删除 1)修改配置文件 修改hdfs-site.xml文件,适当减小dfs.replication的数量,增加dfs.hosts.exclude选项 vi hdfs-site.xml <pr ...

随机推荐

  1. CSS3旋转图片效果收集

    火狐中文网图片效果: [http://i.firefoxchina.cn/?www.firefoxchina.cn] .news-img-wrapper:hover img {     transfo ...

  2. win7 AnkhSVN 安装报错

    重装系统后,需要安装AnkhSVN,结果一直报如下错误 An error occurred during the installation of assembly"Microsoft.VC8 ...

  3. OAuth协议与第三方登录:(QQ,百度,微信,微博)

    OAuth 相当于授权的U盾,提供第三方认证的协议,是个安全相关的协议,作用在于,使用户授权第三方的应用程序访问用户的web资源,并且不需要向第三方应用程序透露自己的密码. 传统互联网:应用于PC端, ...

  4. iOS应用拨打电话

    方法一: 特点: 直接拨打, 不弹出提示. 并且, 拨打完以后, 留在通讯录中, 不返回到原来的应用. //拨打电话 - (void)callPhone:(NSString *)phoneNumber ...

  5. OD调试2---TraceMe

    OD调试2---TraceMe 拆解一个Windows程序要比拆解一个DOS程序容易得多,因为在Windows中,只要API函数被使用,想对寻找蛛丝马迹的人隐藏一些东西是比较困难的.因此分析一个程序, ...

  6. 写一个Windows上的守护进程(4)日志其余

    写一个Windows上的守护进程(4)日志其余 这次把和日志相关的其他东西一并说了. 一.vaformat C++日志接口通常有两种形式:流输入形式,printf形式. 我采用printf形式,因为流 ...

  7. (转) 制作 Clonezilla live 启动盘

    GNU/Linux Method A: Tuxboot 下載 GNU/Linux 版本使用的 Tuxboot 在您的環境 在 GNU/Linux 下, 請依 指示 來執行 Tuxboot 並安裝再生龍 ...

  8. codeforces 337D Book of Evil(dp)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Book of Evil Paladin Manao caught the tra ...

  9. TCP/UDP网络编程的基础知识与基本示例(windows和Linux)

    一.TCP编程的一般步骤 服务器端: 1.创建一个socket,用函数socket() 2.绑定IP地址.端口等信息到socket上,用函数bind() 3.开启监听,用函数listen() 4.接收 ...

  10. 查找mysql数据库文件的存放位置

    在mysql数据库中,有时候并不是很容易找出mysql数据库文件data的存放位置吗,这时就可以使用mysql自带的命令行工具进行查询. 具体命令如下:show variables like '%da ...