首页 > 代码库 > 2017-5-26 正则表达式,js实战(加减数量,全选)
2017-5-26 正则表达式,js实战(加减数量,全选)
1、正则表达式:验证数据格式的准确性。
用正则表达式判断手机号格式是否正确:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title></title> </head> <body> <form id="form1" runat="server"> <div> <asp:textbox ID="Textbox1" runat="server"></asp:textbox> <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> <asp:button ID="Button1" runat="server" text="Button" /> </div> </form> </body> </html> <script type="text/javascript"> document.getElementById("Button1").onclick = function () { document.getElementById("Label1").innerHTML = ""; var s = document.getElementById("Textbox1").value; if (!/^0?(13[0-9]|15[012356789]|17[013678]|18[0-9]|14[57])[0-9]{8}$/.test(s)); { document.getElementById("Label1").innerHTML = "格式错误!"; return false; } return false; } </script>
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } }
2、用加减按钮增加减少数量
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title></title> </head> <body> <form id="form1" runat="server"> <div> <asp:Button ID="btn_jia" value=http://www.mamicode.com/"+" runat="server" Text="+" /> <asp:TextBox ID="TextBox1" runat="server" style="width:30px;"></asp:TextBox> <asp:Button ID="btn_jian" value=http://www.mamicode.com/"-" runat="server" Text="-" /> <asp:Button ID="Button1" runat="server" Text="Button" /> <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> </div> </form> </body> </html> <script type="text/javascript"> document.getElementById("btn_jia").onclick = function () { var s = document.getElementById("TextBox1"); s.value = parseInt(s.value) + 1; } document.getElementById("btn_jian").onclick = function () { var s = document.getElementById("TextBox1"); if (s.value <= 1) { return;} s.value = parseInt(s.value) - 1; } </script>
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class Default2 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { Button1.Click += Button1_Click; } void Button1_Click(object sender, EventArgs e) { Label1.Text = TextBox1.Text; } }
3、用checkbox实现全选
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title></title> </head> <body> <form id="form1" runat="server"> <div> <table style="width:100%;text-align:center;background-color:navy;"> <tr style="color:white;"> <td> <input type="checkbox" id="ckall"/> 全选</td> <td>编号</td> <td>姓名</td> <td>密码</td> <td>昵称</td> <td>性别</td> <td>生日</td> <td>民族</td> </tr> <asp:Repeater ID="Repeater1" runat="server"> <ItemTemplate> <tr style="background-color:white;"> <td> <input type="checkbox" name="ck" value=http://www.mamicode.com/"<%#Eval("ids") %>"/></td> <td><%#Eval("ids") %></td> <td><%#Eval("username") %></td> <td><%#Eval("password") %></td> <td><%#Eval("nickname") %></td> <td><%#Eval("sex") %></td> <td><%#Eval("birthday") %></td> <td><%#Eval("nation") %></td> </tr> </ItemTemplate> </asp:Repeater> </table> <asp:Button ID="Button1" runat="server" Text="Button" /> <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> </div> </form> </body> </html> <script type="text/javascript"> document.getElementById("ckall").onclick = function () { var cks = document.getElementsByName("ck"); for (var i = 0; i < cks.length; i++) { cks[i].checked=this.checked; } var ckss = document.getElementsByName("ck"); for (var i = 0; i < ckss.length; i++) { ckss[i].onclick = function () { var count=0; for (var j = 0; j < ckss.length; j++) { if (ckss[j].checked == false) { count++;} } if (count == 0) { document.getElementById("ckall").checked = true; } else { document.getElementById("ckall").checked = false; } } } } </script>
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class Default3 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if(!IsPostBack) { Repeater1.DataSource = new user1data().selectall(); Repeater1.DataBind(); } Button1.Click += Button1_Click; } void Button1_Click(object sender, EventArgs e) { Label1.Text = Request["ck"]; } }
using System; using System.Collections.Generic; using System.Linq; using System.Web; /// <summary> /// user1data 的摘要说明 /// </summary> public class user1data { DataClassesDataContext con = new DataClassesDataContext(); public user1data() { } public List<user1> selectall() { return con.user1.ToList(); } }
2017-5-26 正则表达式,js实战(加减数量,全选)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。