7个有用的jQuery代码片段分享

jQuery是一款轻量级的JavaScript库,是最流行的客户端HTML脚本之一,它在WEB设计师和开发者中非常的有名,并且有非常多有用的插件和技术帮助WEB开发人员开发出有创意和漂亮的WEB页面

今天我们为jQuery用户分享一些小技巧,这些技巧将帮助你提示你网站布局和应用的创意性和功能性。

一、在新窗口打开链接

用下面的代码,你点击链接即可在新窗口打开:

rush:js;"> $(document).ready(function() { //select all anchor tags that have http in the href //and apply the target=_blank $("a[href^='http']").attr('target','_blank'); });

二、设置等高的列

应用下面的代码,可以使得你的WEB应用每一列高度都想等:

rush:js;">
First Line

Second Line

Third Line

Column Two

三、jQuery预加载图像

这个小技巧可以提升页面加载图片的速度:

rush:js;"> jQuery.preloadImagesInWebPage = function() { for (var ctr = 0; ctr & lt; arguments.length; ctr++) { jQuery("").attr("src",arguments[ctr]); } } // 使用方法: $.preloadImages("image1.gif","image2.gif","image3.gif"); // 检查图片是否被加载 $('#imageObject').attr('src','image1.gif').load(function() { alert('The image has been loaded…'); });

四、禁用鼠标右键

rush:js;"> $(document).ready(function() { //catch the right-click context menu $(document).bind("contextmenu",function(e) { //warning prompt - optional alert("No right-clicking!"); //delete the default context menu return false; }); });

五、设定计时器

rush:js;"> $(document).ready(function() { window.setTimeout(function() { // some code },500); });

六、计算子元素的个数

rush:js;">

七、把元素定位到页面中间

rush:js;">

相关文章

页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: <span id=&quot...
jQuery 添加水印 <script src="../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...