2010-01-14 83 views
0

我想將查詢UI效果應用於元素,具體取決於URL中的#。如何將jQuery UI效果應用於URL中的#name元素

ie:當加載www.mysite.com/page.html#name時,effect()應用於帶有#name id的元素,而加載www.mysite.com/page.html#othername會有效果( )用#othername id和www.mysite.com/page03.html適用於該元素將不起作用()。

回答

0

您可以使用

window.location.hash得到下面的#符號,包括#符號的URL的一部分。

window.location

在你的情況下,它會返回#name

$(function(){ 
    $("#btn1").click(function(){ 
     var elemName = window.location.hash; 
     /* $(elemName) will retrieve the jQuery element with the corresponding 
       id and you can apply the effect to this element.*/ 
    }); 
}); 
+0

它就像一個魅力 謝謝! – LapinLove404 2010-01-14 12:15:07

相關問題