나는 두 개의 이미지를 표시하기 위해 innerHTML을 변경하기 위해 HTML에 2 개의 div 요소가 있고 그 다음에 javascript가 있습니다.DIV 안에있는 이미지 주소를 얻는 방법은 무엇입니까?
하지만 어떻게해야할까요? 현재 내 메서드는 항상 "undefined"를 반환합니다. 다음은 내 코드입니다 :
HTML :
<div id ="demo5"
style="
top: 45px;
left: 30px;
position: fixed;
z-index: 1;
visibility: show;">
</div>
<div id ="demo6"
style="
top: 45px;
left: 55px;
position: fixed;
z-index: 1;
visibility: show;">
</div>
자바 스크립트 :
이var hand = [1.1,1.2,1.3,1.4,2.1,2.2,2.3,2.4,3.1,3.2,3.3,3.4,4.1,4.2,4.3,4.4,5.1,5.2,5.3,5.4,6.1,6.2,6.3,6.4,7.1,7.2,7.3,7.4,8.1,8.2,8.3,8.4,9.1,9.2,9.3,9.4,10.1,10.2,10.3,10.4,11.1,11.2,11.3,11.4,12.1,12.2,12.3,12.4,13.1,13.2,13.3,13.4]
a = Math.floor(Math.random() * 52)
b = Math.floor(Math.random() * 52)
do {b = Math.floor(Math.random() * 52)}
while (b==a)
var address1 = hand[a] + ".jpg"
var address2 = hand[b] + ".jpg"
var path = path || 'http://111.com/';
document.getElementById("demo5").innerHTML = '<img src="' + path + address5 + '" >'; ;
document.getElementById("demo6").innerHTML = '<img src="' + path + address6 + '" alt = "">';
function myFunction() {
var x = document.getElementById("demo5").src
document.getElementById("demo").innerHTML = x;
}
내가 사용한 코드는 getElementById ('demo5')입니다. getElementsByTagName ('img') [0] .src.split ("/"). pop(). split (".") [ 0] – Frostless