2013-02-18 39 views
1

我遇到了jQuery和錨定問題,涉及微軟桌面Windows應用程序的錨點。 我工作的一個內部應用程序提供的鏈接,例如:硬盤驅動器鏈接的綁定操作

<a id="launch-21" class="launch-app" href="c:\windows\explorer.exe" target="_blank"> 

我想針對含有例如窗戶,以綁定以下操作中的所有鏈接:

jQuery('a[href*="windows"]').click(function(event){ 
    alert("use this link in your windows workstation"); 
    event.preventDefault(); 
}); 

這有沒有絕對沒有效果。 但是,當我運行下面的選擇器,元素很好地返回。

看來治療不適用於硬盤鏈接? jQuery('a [href * =「windows」]') 有人幫我嗎?

+0

當你說「沒有效果」時,你的意思是什麼都沒有發生? 這些鏈接是靜態的還是動態的?事件綁定何時發生在您的代碼中? – 2013-02-18 17:19:51

回答

0

你的代碼似乎沒有任何問題的工作,

也許你$(document).ready運行之前被觸發,或有問題的鏈接在DOM被加載並準備使用JavaScript解析。

試着改變你的JavaScript來:

I've created a fiddle for this, you may test it there

jQuery(document).ready(function(){ 
    jQuery('a[href*="windows"]').click(function(event){ 
     var link = jQuery(this).attr("href"); 
     window.prompt("use this link in your windows workstation", link); 
     event.preventDefault(); 
    }); 
}); 

(請注意,我把爲了做一些測試,改變你的警報提示的自由)

另外,您也可以在關閉<body>標籤之前將您的javascript移動到頁面的末尾。