• JS各种小问题


    ajax参数加入时间,避免请求缓存(第一次执行,之后都不执行)

       $.ajax({
                    type: "get",
                    url: "Handler.ashx",
                    dataType: 'text',
                  data:{i:j,t:new Date().getTime()},   //参数加入时间,            
                    success: function(result) {
                      alert(result);
                    }
                });
    

    js以属性来取值,比如说:

    <div x="123" xyz="1">这是个div层</div>
    <script>	
    	alert($("div[x=123]").html());
    </script>
    

     三

    常用控件取值

     复选框:  $("input[type=checkbox][checked]").val();
    
    单选按钮:   $("input[type=radio][checked]").val();
    
    下拉框:     $("#a option:selected").val();
    

     四

    js获得父节点的子节点集合,以及获得子节点的标签类型

                var td = $(img).get(0).parentNode.parentNode.childNodes;
                //获得对应的文本框id,隐藏域id
                for (var i = 0; i < td.length; i++) {
                    if (td[i].type == "hidden") {
                        hiddenId = $(td[i]).attr("id");
                    }
                    if (td[i].type == "text") {
                        textId = $(td[i]).attr("id");
                    }
                }
    

    五,js比较时间

    </script>
    
        <%--添加日期提示--%>
    
        <script type="text/javascript">
              
        $(document).ready(function() {
        $("#btnSave").click(function() {
            var choiceDate = $("#txtDutyTime").val();
            //替换字符,变成标准格式
            choiceDate = choiceDate.replace("-", "/"); 
            //parse()是Date对象的静态方法,可以把时间的字符串转化为时间类型,要是标准的时间格式    
            choiceDate = new Date(Date.parse(choiceDate));
            var now = new Date();
            var nowStr = now.getFullYear() + "-" + (now.getMonth() + 1) + "-" + now.getDate();
            var choiceDateStr = choiceDate.getFullYear() + "-" + (choiceDate.getMonth() + 1) + "-" + choiceDate.getDate();
    
            if (nowStr != choiceDateStr) {
                if (now > choiceDate) {
                    alert("请选择当前日期之后的日期");
                    $("#txtDutyTime").focus();
                    $("#txtDutyTime").val('');
                    return false;
                } else return true;
            }
        });
    });
        </script>
    

     六,js打印指定区域内的内容——只要把指定区域的html赋给body即可

            //调用浏览器的打印功能打印指定区域 
            function printDoc() {
              document.body.innerHTML=document.getElementById('div').innerHTML;
              window.print(); 
            }
    

     js正则验证

    var a=/^d{18}$/;
    a.test('123');

     单选框

    $('input[name="rbltype"]:checked').val();
     
  • 相关阅读:
    设计模式(08):结构型模式(二) 桥接模式(Bridge)
    设计模式(07):结构型模式(一) 适配器模式(Adapter)
    设计模式(06):创建型模式(五) 原型模式(Prototype)
    node.js获取cookie
    排序算法[转]
    Observer(观察者)设计模式[转]
    c#发送Http请求
    win+R下的命令
    display:inline、block、inline-block的区别
    Redis安装
  • 原文地址:https://www.cnblogs.com/xushining/p/3181753.html
Copyright © 2020-2023  润新知