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();

 

 

 

 

 

 

 

 

 

 

 

posted on 2013-07-10 11:25  小小乌龟把头藏  阅读(255)  评论(0编辑  收藏  举报