首页 > 代码库 > !!!常用jquery代码

!!!常用jquery代码

文档:

<!doctype html><html><head><meta charset="utf-8"><title></title><!-- <link href="http://www.mamicode.com/css.css" type="text/css" rel="stylesheet" /> --><!-- <script src="http://www.expai.com/js/jquery-1.8.3.min.js"></script> --><!-- <script src="http://code.jquery.com/jquery-2.1.1.min.js"></script> --><!-- <script src="http://code.jquery.com/jquery-1.7.2.min.js"></script> --><!-- <script src="http://code.jquery.com/jquery-1.8.3.min.js"></script> --><script src="http://code.jquery.com/jquery-1.11.1.min.js"></script><script type="text/javascript">$(function(){    $("#div1").click(function(){    });});</script><style type="text/css"></style></head><body></body></html>

 

事件:

$(window).resize(function() {});$(".div1").live("mouseenter",function(event){});$(".div1").live("mouseleave",function(event){});$(".div1").bind("click",function(){});$(document).live("click",function(event){    event.stopPropagation();});

 

AJAX:

var requestUrl="http://localhost/1.html?callback=?";$.ajax({    type : "get",    async:true,    url : requestUrl,    data : "channelid=7&current=1&rowSize=4",    dataType : "jsonp",    success :function(data){        console.log("--------(xxxxx)-----success");    },    error:function(data){        console.log("error: (xxxxx)");    }});

 

 

遍历:

$("li").each(function(){    alert($(this).html())});
var ee=$("li");var len=ee.length;for(var i=0;i<len;i++)    if(    $("li").eq(i).is(":visible")==true  ){        alert("显示");    }else{        alert("none");    }}

 

动画、显示隐藏:

$(".dot0").stop(true,true).show();

 

延时:

setTimeout(function(){},3000);

 

 

 

 

 

 

 

检测浏览器:

EpBrowser = {    version: 0,    core: "",    userAgent: "",//userAgent    init:function() {        var ua = navigator.userAgent.toLowerCase();        var s;        var name =‘‘;        var ver = 0;        this.userAgent=ua;        (s = ua.match(/msie ([\d.]+)/)) ? this._set("ie", this._setVersion(s[1])):        (s = ua.match(/firefox\/([\d.]+)/)) ? this._set("firefox", this._setVersion(s[1])) :        (s = ua.match(/chrome\/([\d.]+)/)) ? this._set("chrome", this._setVersion(s[1])) :        (s = ua.match(/opera.([\d.]+)/)) ? this._set("opera", this._setVersion(s[1])) :        (s = ua.match(/version\/([\d.]+).*safari/)) ? this._set("safari", this._setVersion(s[1])) : 0;    },    _setVersion:function(ver,floatLength) {        ver = (‘‘ + ver).replace(/_/g, ‘.‘);        ver = String(ver).split(‘.‘);        return parseInt(ver[0]);    },    _set:function(bname,bver) {        this.core=bname;        this.version=bver;    }
  log:function(msg) {
	if(  (EpBrowser.core=="chrome")  ){//chrome		console.log("log>>    "+msg);	}  }
};