간단한 해결책이 있기를 바랍니다. 각 페이지로드시 임의의 이미지를 표시하는 JavaScript 코드가 있습니다. image1.jpg
은 image_1.html
으로 표시되는 것처럼 각 이미지는 자체 페이지로 연결됩니다. image3.jpg
에 관해서는 그 이미지에 대한 페이지가 없습니다.자바 스크립트 무작위 이미지 롤오버 및 링크 사용 안 함
나는 공란으로 남겨두고 이미지가 무작위로 표시 될 때 어딘가에 링크되어 있음을 나타내는 롤오버가 필요 없다. 아래 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"
이 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 === '')는 큰 따옴표가 아닌 두 개의 작은 따옴표입니다. 행운을 빕니다! –