jquery是一款轻量级的javascript库,是最流行的客户端html脚本之一,它在web设计师和开发者中非常的有名,并且有非常多有用的插件和技术。
本文我们将为大家分享一些jquery小技巧:
一、在新窗口打开链接
用下面的代码,你点击链接即可在新窗口打开:
$(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应用每一列高度都想等:
first line
second line
third line
column two
三、jquery预加载图像
这个小技巧可以提升页面加载图片的速度:
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…');});
四、禁用鼠标右键
$(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; });});
五、设定计时器
$(document).ready(function() { window.settimeout(function() { // some code }, 500);});
六、计算子元素的个数
七、把元素定位到页面中间
读到这里的朋友就知道你没有错过学习的机会,把这些小技巧积累起来,一定会帮助大家设计出有创意和精美的web页面。
