2011-11-16 15 views
0

我正在玩一個非常簡單的jquery modal windows。它通過點擊打開模式窗口如何通過URL屬性製作JavaScript動作?

<a href="#" id="clickMe">Click Me</a> 

如何通過向URL添加屬性來實現此JavaScript操作index.php?q = clickMe或index.html#clickMe

我的意思是當訪問index.html的網頁(使用q = clickMe或#clickMe)時,使用打開的模式加載頁面。換句話說,該屬性在jQuery的id =「clickMe」上扮演CLICK的角色。

+0

不是一個答案,但我想知道爲什麼你必須做點擊後,你有url參數?你能不能直接在你得到參數後直接做模態? – Reigel

+0

是的,我只想在url有給定參數時使用模式。這確實與點擊相同。我想顯示模式,如果訪問index.html#東西 – Googlebot

回答

1

您需要處理document.ready()中的QueryString或URL哈希。 這裏是處理哈希#clickMe

$(document).ready(function() { 
    if (window.location.hash == "#clickMe") { 
    //open modal 
    } 
}); 
0

嘗試使用jquery.url插件。

1

第一,我會得到一個jQuery插件讀取querysting變量的例子 - 像getUrlParam

然後,你可以在腳本做

$(document).ready(function() { 
    if ($(document).getUrlParam("activate-click").length > 0) { 
    $("#clickMe").click(); 
    } 
});