标签:
用下面的代码,你点击链接即可在新窗口打开:
$(document).ready(function() { $("a[href^=‘http‘]").attr(‘target‘,‘_blank‘); });
应用下面的代码,可以使得你的WEB应用每一列高度都想等:
<div class="equalHeight" style="border:1px solid"> <p>First Line</p> <p>Second Line</p> <p>Third Line</p> </div> <div class="equalHeight" style="border:1px solid"> <p>Column Two</p> </div> <script src="http://apps.bdimg.com/libs/jquery/1.11.1/jquery.min.js"></script> <script> $(document).ready(function() { equalHeight(‘.equalHeight‘); }); //global variable, this will store the highest height value var maxHeight = 0; function equalHeight(col) { //Get all the element with class = col col = $(col); //Loop all the col col.each(function() { //Store the highest value if ($(this).height() > maxHeight) { maxHeight = $(this).height(); } }); //Set the height col.height(maxHeight); } </script>
这个小技巧可以提升页面加载图片的速度:
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); });
<div id="foo"> <div id="bar"></div> <div id="baz"> <div id="biz"></div> <span><span></span></span> </div> </div> <script src="http://apps.bdimg.com/libs/jquery/1.11.1/jquery.min.js"></script> <script type="text/javascript"> //jQuery code to count child elements $("#foo > div").size() alert($("#foo > div").size()) </script>
<div id="foo" style="width:200px;height: 200px;background: #ccc;"></div> <script src="http://apps.bdimg.com/libs/jquery/1.11.1/jquery.min.js"></script> <script type="text/javascript"> jQuery.fn.center = function() { this.css("position", "absolute"); this.css("top", ($(window).height() - this.height()) / 2 + $(window).scrollTop() + "px"); this.css("left", ($(window).width() - this.width()) / 2 + $(window).scrollLeft() + "px"); return this; } //Use the above function as: $(‘#foo‘).center(); </script>
THS原文分享!
标签:
原文地址:http://www.cnblogs.com/htzan/p/4537840.html