前端(js+JQuery非空校验)

1、倒退://history.go(-1);//javascript: history.back();

两种页面跳转的方法:

//Response.Write("<script>alert('false');window.location.href='QuestionList.aspx';</script>");

 Page.ClientScript.RegisterStartupScript(GetType(), "js", "<script>alert('操作有误');window.location.href='QuestionList.aspx';</script>");
            

2、删除时的确认弹框,调用时:OnClientClick="return BoolDelete();//注:别忘了return(需要返回值)

<script language="javascript" type="text/javascript">
    function BollDele() {
        var conet = "";

        conet = "确定要删除?";


        if (confirm(conet)) {
            return true;
        } else {
            return false;
        }
    }
</script>

3、时间查询:

          if (!string.IsNullOrEmpty(BeginDate))
            {
                where = where + " and BeginDate>='" + BeginDate + "'";
            }
            if (!string.IsNullOrEmpty(EndDate))
            {
                where = where + " and EndDate<='" + EndDate + "'";
            }

4、前端输入框的非空判断(失去焦点即显示提示)、点击新增自动获取为空输入框的焦点。

事件调用方法:

onblur="tip(7,checktdatetimeEnd);"
<script src="../js/jquery-1.8.2.min.js" type="text/javascript"></script>
<script src="../js/laydate/laydate.js" type="text/javascript"></script>
    <script type="text/javascript">

        var start = {
            elem: '#datetimeStart',
            format: 'YYYY-MM-DD',
            max: '2099-06-16', //最大日期
            istime: false,
            istoday: true,

            choose: function (datas) {
                tip(6, checktdatetimeStart);
                end.min = datas; //开始日选好后,重置结束日的最小日期
                end.start = datas //将结束日的初始值设定为开始日
            }
        };
        var end = {
            elem: '#datetimeEnd',
            format: 'YYYY-MM-DD',
            max: '2099-06-16',
            istime: false,
            istoday: true,

            choose: function (datas) {
                tip(7, checktdatetimeEnd);
                start.max = datas; //结束日选好后,重置开始日的最大日期
            }
        };
        laydate(start);
        laydate(end);

        
        
        

        sessionStorage.setItem('2', 'false');
        function checktDDCompanyName() {
            var DDCompanyName = $("#DDCompanyName").val();
            if ($.trim(DDCompanyName) == "") {
                return "▲请选择客户名称!";
            }
            return "";
        }

        
        sessionStorage.setItem('3', 'false');
        function checktTxtActivityTitle(){
          var txtActivityTitle = $("#txtActivityTitle").val();
            if ($.trim(txtActivityTitle) == "") {
                return "▲请填写活动名称!";
            }
            return "";
        }

        sessionStorage.setItem('4', 'false');
        function checktDDDatyType() {
            var DDDatyType = $("#DDDatyType").val();
            if ($.trim(DDDatyType) == "") {
                return "▲请选择活动类型!";
            }
            return "";
        }
        sessionStorage.setItem('5', 'false');
        function checkttxtContent() {
            var txtContent = $("#txtContent").val();
            if ($.trim(txtContent) == "") {

                return "▲请填写活动描述!";
            }
            return "";
        }
        sessionStorage.setItem('6', 'false');
        function checktdatetimeStart() {
            var datetimeStart = $("#datetimeStart").val();
            if ($.trim(datetimeStart) == "") {
                return "▲请选择开始时间!";
            }
            return "";
        }

        sessionStorage.setItem('7', 'false');
        function checktdatetimeEnd() {
            var datetimeEnd = $("#datetimeEnd").val();
            if ($.trim(datetimeEnd) == "") {
                return "▲请选择结束时间!";
            }
            return "";
        }

        sessionStorage.setItem('9', 'false');
        function checkttxtProjectNum() {
            var txtProjectNum = $("#txtProjectNum").val();
            if ($.trim(txtProjectNum) == "") {
                return "▲请填写项目编号!";
            }
            return "";
        }
         
        function tip(num, check) {
            if (sessionStorage.getItem(num.toString()) != null) {
                if (sessionStorage.getItem(num.toString()).toString() == 'false') {
                    var tipmsg = check();
                    if (tipmsg != "") {
                        addtip(parseInt(num), tipmsg);
                        sessionStorage.setItem(num.toString(), 'true');
                       
                    }
                }
                else {
                    var tipmsg = check();
                    if (tipmsg == "")
                    {
                        deltip(num);
                        sessionStorage.setItem(num.toString(), 'false');
                    }
                    
                }

            }
            //deltip();
        }

//        <asp:Label runat="server" Text="Label" style="font-color: red"></asp:Label>
        function addtip(num,text) {
            var subtable = document.getElementById('table1');
            var i = subtable.rows.length;
            var addnum = 0;
            for (var i = 0; i < num * 2 + addnum; i++) {
                id = subtable.childNodes[1].childNodes[i].id;
                if (id !== null && id !== undefined && id.toString() !== "") {
                    addnum++;
                }
            }
            console.log("addnum:" + addnum);
            var addrow = subtable.insertRow(num + addnum); //添加一行到第一行的位置行 
            addrow.innerHTML += '<td colspan="2" style="text-align: center"><asp:Label ID="Label1" runat="server" Text="' + text + '" class="tip"></asp:Label></td>';
            //var col1 = addrow.insertCell(0); //添加列
            addrow.id = num.toString();


        }
        function deltip(num) {

            var subtable = document.getElementById('table1');
            var body = subtable.childNodes[1];

            console.log(body.childNodes.length);
            for (var i = 0; i < body.childNodes.length; i++) {
                console.log(body.childNodes[i].id);
                if (body.childNodes[i].id == num.toString()) {
                    body.removeChild(body.childNodes[i]);
                }
            }
        }
        function getFocus(id) {
            try {
                var a = document.getElementById(id);
                a.focus();
                a.select();
            } catch (e) { }
        }
        function CheckReg() {
            tip(2, checktDDCompanyName);
            console.log(sessionStorage.getItem("2").toString());
            if (sessionStorage.getItem("2").toString() == 'true') {
                getFocus("DDCompanyName");
                return;
            }
            tip(3, checktTxtActivityTitle);
            console.log(sessionStorage.getItem("3").toString());
            if (sessionStorage.getItem("3").toString() == 'true') {
                getFocus("txtActivityTitle");
                return;
            }
            tip(4, checktDDDatyType);
            console.log(sessionStorage.getItem("4").toString());
            if (sessionStorage.getItem("4").toString() == 'true') {
                getFocus("DDDatyType");
                return;
            }
            tip(5, checkttxtContent);
            console.log(sessionStorage.getItem("5").toString());
            if (sessionStorage.getItem("5").toString() == 'true') {
                getFocus("txtContent");
                return;
            }
            tip(6, checktdatetimeStart);
            console.log(sessionStorage.getItem("6").toString());
            if (sessionStorage.getItem("6").toString() == 'true') {
                getFocus("datetimeStart");
                return;
            }
            tip(7, checktdatetimeEnd);
            console.log(sessionStorage.getItem("7").toString());
            if (sessionStorage.getItem("7").toString() == 'true') {
                getFocus("datetimeEnd");
                return;
            }
            tip(9, checkttxtProjectNum);
            console.log(sessionStorage.getItem("9").toString());
            if (sessionStorage.getItem("9").toString() == 'true') {
                getFocus("txtProjectNum");
                return;
            }
        }
        if ('<%=Session["First"] %>' == 'false') {
            CheckReg();
        }
    </script>

后台设置:

        if (!IsPostBack)
            {
                DDBind();
                Session["First"] = "true";
               // Response.Write("<script>alert('true');</script>");
            }
            else
            {
                Session["First"] = "false";
                //Response.Write("<script>alert('false');</script>");
            }

 

转载于:https://my.oschina.net/8824/blog/1922260

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值