我希望這有一個簡單的解決方案。我有一個JavaScript代碼,可以在每個頁面加載中顯示隨機圖像。每個圖像鏈接到它自己的頁面,如您所見image1.jpg
轉到image_1.html
。至於image3.jpg
我沒有該圖像的頁面。Java腳本隨機圖像禁用翻轉和鏈接
我想讓它保持空白,當圖像隨機顯示時,我不希望任何形式的滾動,表明它鏈接到某個地方。在下面的JavaScript代碼中,我指定了我認爲需要修改以獲取所需內容的JavaScript區域。
任何提示或建議將有所幫助。謝謝。
var imagenumber = 1 ;
var randomnumber = Math.random() ;
var rand1 = Math.round((imagenumber-1) * randomnumber) + 1 ;
images = new Array
images[1] = "assets/image1.jpg"
images[2] = "assets/image2.jpg"
images[3] = "assets/image3.jpg"
images[4] = "assets/image4.jpg"
var image = images[rand1] ;
var linknumber = 1;
var img1 = Math.round((linknumber-1) * randomnumber) + 1 ;
links = new Array
links[1] = "image_1.html"
links[2] = "image_2.html"
links[3] = "" // <-- what do I place here to NOT have a link?
links[4] = "image_3.html"
links[5] = "image_4.html"
我在javascript的結尾找到了這個document.write代碼。我相信它控制着鏈接存在的指示。如果我刪除了 from the code then I lose all the links but the images still appear. Which is good but not exactly what I'm trying to achieve. I think I need a new document.write code that makes the array look for a blank or other value like you are describing. - I hope I'm on the right track here. Thanks! var link = links[img1]; document.write(''); –
你是在正確的軌道上,是的。取而代之的是放出錨標籤,您需要制定一個條件來選擇是放出錨標籤還是不放出,具體取決於鏈接的值是否爲空,如下所示:if(link ===' '){document.write(''); } else {document.write(''); } - 我使用了一個橢圓截斷正在寫出的HTML,但應該很明顯,第一個塊只是圖像標籤,第二個是帶有圖像標籤的錨標籤。請注意,(link ==='')是兩個單引號,而不是一個雙引號。祝你好運! –