很是好的javascript 代碼

 

 與其餘Javascript類庫衝突解決方案

$(document).ready(function()
 {

var $jq = jQuery.noConflict();

$jq('#id').show();

});
使元素居屏幕中間位置

$(document).ready(function() 
{

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;

 }

 $("#id").center();

 });

 

使整個DIV可點擊

 $(document).ready(function()
 {

$("div").click(function()
{

window.location=$(this).find("a").attr("href"); return false;

 });

 // how to use

 <DIV><A href="index.html">home</A></DIV>



});
jQuery延時加載功能view plaincopy to clipboardprint?

$(document).ready(function() 
{
window.setTimeout(function() 
{



 }, 1000);

 });
得到鼠標指針XY值

 $(document).ready(function()
 {

 $().mousemove(function(e)
{

 $('#XY').html("X Axis : " + e.pageX + " | Y Axis " + e.pageY);

 });

 // how to use

<DIV id=XY></DIV>

});
返回頁面頂部功能
 $(document).ready(function() 
{
 $('a[href*=#]').click(function() 
{
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
 && location.hostname == this.hostname) 
{
 var $target = $(this.hash);
 $target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
 if ($target.length) 
{
 var targetOffset = $target.offset().top;
 $('html,body').animate({scrollTop: targetOffset}, 900);
 return false;
 }
}
 });

 // how to use
 <A name=top></A>
 <A href="#top">go to top</A>
 });
 頁面樣式切換
 $(document).ready(function() 
{
 $("a.Styleswitcher").click(function() 
{
 $('link[rel=stylesheet]').attr('href' , $(this).attr('rel'));
});
// how to use
 <LINK href="default.css" type=text/css rel=stylesheet>
 // the links
 <A class=Styleswitcher href="#" rel=default.css>Default Theme</A>

<A class=Styleswitcher href="#" rel=red.css>Red Theme</A>
<A class=Styleswitcher href="#" rel=blue.css>Blue Theme</A>
});
 預加載圖片
 $(document).ready(function() 
{
 jQuery.preloadImages = function()
 {
 for(var i = 0; i").attr("src", arguments[i]);
 }
};

// how to use
$.preloadImages("image1.jpg");

 });
禁止右鍵點擊

 $(document).ready(function()
{
$(document).bind("contextmenu",function(e)
{
 return false;
});
});

 

用下面方法,能夠簡單又可靠的獲得一個變量是否一個數組:
Object.prototype.toString.apply(value) === '[object Array]'
相關文章
相關標籤/搜索