如果你不能因爲某些原因,試試這個當前活動圖像上
$("active image identifier selector a").attr("href", "link to add");
$("all images selector").not("active image identifier selector").find("a").removeAttr("href")
介意你使用removeAttr不會禁用鏈接,它完全刪除它,不知道如果那就是你想要做的。只是要確認,你是否希望鏈接停用或刪除。
e.preventDefault只禁用鏈接但不刪除它。如果你有第二個圖像活動,你做了像$(「圖像a」),attr(「href」,「鏈接添加」),你怎麼知道什麼鏈接添加到該圖像和之前圖像時,他們變得活躍,因爲你幾乎丟棄了href屬性。
一個解決方案,我將建議是存儲在數據屬性的鏈接,鏈接像
//store href in link data for each link to be deactivated
$("all images selector").not("active image identifier selector").each(function(){
var $this = $(this);
//get url of link
var url = $this.attr("href");
//store url in a data attribute for that link
$this.data("my-url", url);
$(this).removeAttr("href");
});
//get data attribute of active image and readd href attribute
$("active image identifier selector a").attr("href", $("active image identifier selector a").data("my-url"));
試試這個,讓我知道是否有幫助。 請注意,它不是最有效的方法。可能會有更多的優化函數來循環鏈接,但讓它起作用是我首先想到的。
乾杯。
$('a')。removeAttr('href') –
你的意思是谷歌不喜歡。你說它不是freindly? –
您能否展示一段代碼片段,將ypu帶到幻燈片中的下一張圖片? –