Posts Tagged ‘jquery’

13 11 2009

使用Google CDN服务提供的jQuery库

bigCat Posted in JavaScript - 1 Comment

< script type="text/javascript" src="http://www.google.com/jsapi"></script>\r\n\r\n加载jQuery,可以这样使用:\r\ngoogle.load("jquery","1.3.2");\r\n\r\n1.3就是最新的1.3.x\r\n\r\n1就是最新的1.x.x\r\n\r\n这样我们就从Google的最近的CDN镜像上加载了jQuery 1.3.2版的js库,接下来就可以正常写js代码了。不过,即使是Google的CDN镜像,下载也毕竟是需要时间的,万一代码库还没有下载完而浏览器 已经解释到了下面的代码了怎么办?我们可以设定在js库加载完以后才开始执行js:\r\ngoogle.setOnLoadCallback(function(){//要执行的代码});\r\n更多有关google jsapi的相关介绍和文档,可以参考:google AJAX 库 API\r\n\r\n除了jQuery,Google还提供供了以下这些js框架/库的API:\r\njQuery UI\r\nPrototype\r\nscript.aculo.us\r\nMooTools

24 09 2009

jQuery 判断 id 是否存在

bigCat Posted in JavaScript - 0 Comment

if($("#ooxx")[0]){alert('愿局域网与你同在')}

26 08 2009

jquery $.ajax .abort

bigCat Posted in JavaScript - 0 Comment

ajax函数有个xhr选项,它返回一个XMLHttpRequest对象,这个对象用于ajax请求\r\n而XMLHttpRequest对象有abort方法,所以先将这个对象传给ajax函数,再调用它的abort方法即可\r\n\r\n此外,beforeSend选项可以拿到这个对象,在里面赋给外部变量,就能在外部引用了

10 08 2009

jquery 判断IE6

bigCat Posted in JavaScript - 0 Comment

isIE6 = $.browser.msie && (parseInt($.browser.version) == 6);\r\n\r\n不知道是不是这么玩的...

10 08 2009

jQuery 操作Cookie 的函数

bigCat Posted in JavaScript - 0 Comment
jQuery.cookie = function(name, value, options) {\r\n    if (typeof value != 'undefined') {\r\n        options = options || {};\r\n        if (value === null) {\r\n            value = '';\r\n            options = $.extend({}, options);\r\n            options.expires = -1;\r\n        }\r\n        var expires = '';\r\n        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {\r\n            var date;\r\n            if (typeof options.expires == 'number') {\r\n                date = new Date();\r\n                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));\r\n            } else {\r\n                date = options.expires;\r\n            }\r\n            expires = '; expires=' + date.toUTCString();\r\n        }\r\n        var path = options.path ? '; path=' + (options.path) : '';\r\n        var domain = options.domain ? '; domain=' + (options.domain) : '';\r\n        var secure = options.secure ? '; secure' : '';\r\n        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');\r\n    } else {\r\n        var cookieValue = null;\r\n        if (document.cookie && document.cookie != '') {\r\n            var cookies = document.cookie.split(';');\r\n            for (var i = 0; i < cookies.length; i++) {\r\n                var cookie = jQuery.trim(cookies[i]);\r\n                if (cookie.substring(0, name.length + 1) == (name + '=')) {\r\n                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));\r\n                    break;\r\n                }\r\n            }\r\n        }\r\n        return cookieValue;\r\n    }\r\n};\r\n\r\n//调用\r\n\r\n
$(document).ready(function() {\r\n$('#wCookies').click(function(){\r\n  $.cookie('name', 'test',{expires: 7});				  \r\n});\r\n$('#rCookies').click(function(){\r\n  var test = $.cookie('name');\r\n  alert (test);\r\n});\r\n$('#dCookies').click(function(){\r\n	$.cookie('name', null);							  \r\n});\r\n});

\r\n

Host: (miao) | Word: Press | Code: HTML5