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="+" runat="server" Text="+" />
        <asp:TextBox ID="TextBox1" runat="server" style="width:30px;"></asp:TextBox>
        <asp:Button ID="btn_jian" value="-" 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="<%#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();
    }
}
时间: 2024-11-04 13:06:49

2017-5-26 正则表达式,js实战(加减数量,全选)的相关文章

转:JS日期加减,日期运算

原文 出处http://hi.baidu.com/tonlywang/item/685fba8933a2a756e73d1950 一.日期减去天数等于第二个日期 function cc(dd,dadd) ...{ //可以加上错误处理 var a = new Date(dd) a = a.valueOf() a = a - dadd * 24 * 60 * 60 * 1000 a = new Date(a) alert(a.getFullYear() + "年" + (a.getMon

js 时间加减

//js格式化时间 "yyyy-MM-dd hh:mm:ss" Date.prototype.Format = function (fmt) { var o = { "M+": this.getMonth() + 1, //月份 "d+": this.getDate(), //日 "h+": this.getHours(), //小时 "m+": this.getMinutes(), //分 "s

分别用js和jq实现百度全选反选效果

js实现过程 1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8"> 5 <title>Title</title> 6 <style> 7 li { 8 height: 30px; 9 line-height:30px; 10 list-style: none; 11 font-size: 24px

js 浮点数加减问题

/** ** 加法函数,用来得到精确的加法结果 ** 说明:javascript的加法结果会有误差,在两个浮点数相加的时候会比较明显.这个函数返回较为精确的加法结果. ** 调用:accAdd(arg1,arg2) ** 返回值:arg1加上arg2的精确结果 **/ function accAdd(arg1, arg2) { var r1, r2, m, c; try { r1 = arg1.toString().split(".")[1].length; } catch (e) {

Js日期加减(天数),时间加减,日期运算,可直接调用

根据传入的日期做加减法计算,整数为加法,负数为减法,但是是天.  num可传入: 1,2,3,-1,-2,-3等,默认是加一天:date可传入: 2017-01-01格式的,不传的话默认是当天日期. function dateChange(num = 1,date = false) { if (!date) { date = new Date();//没有传入值时,默认是当前日期 date = date.getFullYear() + '-' + (date.getMonth() + 1) +

JS日期加减

JS日期加减,日期运算

一.日期减去天数等于第二个日期 function cc(dd,dadd){//可以加上错误处理var a = new Date(dd)a = a.valueOf()a = a - dadd * 24 * 60 * 60 * 1000a = new Date(a)alert(a.getFullYear() + "年" + (a.getMonth() + 1) + "月" + a.getDate() + "日")}cc("12/23/200

js小数加减时精度不准确

// 返回值:arg1加上arg2的精确结果 function accAdd(arg1, arg2) { var r1, r2, m; try { r1 = arg1.toString().split(".")[1].length } catch (e) { r1 = 0 }; try { r2 = arg2.toString().split(".")[1].length } catch (e) { r2 = 0 }; m = Math.pow(10, Math.m

Goods:购物车条目加减数量实现

list.jsp 1 //给减号添加click事件 2 3 $(".jian") 4 .click( 5 function() { 6 //获取cartItemId 7 var id = $(this).attr("id").substring(0, 32); 8 var quantity = $("#" + id + "Quantity").val(); 9 //判断当前数量是否为1 如果为1就不是修改数量啦 而是删除 10