document.write()로 자바 스크립트 파일에 이미지를 게시하려고합니다. 문제는 내가 그것을 시도 할 때, 이미지는 항상 깨진다는 것입니다. 여기에 코드가 있습니다. 태그를 잘못 쓰고 있습니까? 비 자바 스크립트 페이지의 이미지를 테스트 해 보았는데 정상적으로 표시되는 것 같습니다.document.write()로 페이지에 이미지 표시
var replay = "yes";
var userChoice = prompt("Do you choose rock, paper or scissors?");
userChoice = userChoice.toLowerCase();
var computerChoice = Math.random();
if (computerChoice < 0.34) {
computerChoice = "rock";
} else if (computerChoice <= 0.67) {
computerChoice = "paper";
} else {
computerChoice = "scissors";
}
var compare = function (choice1, choice2) {
if (choice1 === choice2) {
document.write("The result is a tie!");
}
if (choice1 === "rock") {
if (choice2 === "scissors") {
document.write('<img src="images\orna.jpg\">');
} else {
document.write("Computer chose paper. Computer wins.");
}
}
if (choice1 === "paper") {
if (choice2 === "scissors") {
document.write("Computer chose scissors. Computer wins.");
} else {
document.write("Computer chose rock. Player wins.");
}
}
if (choice1 === "scissors") {
if (choice2 === "paper") {
document.write("Computer chose paper. Player wins.");
} else {
document.write("Computer chose scissors. Computer wins.");
}
}
};
compare(userChoice, computerChoice);
이미지의 일부에 전체 URL이 무엇 일 것입니다 :
또는 문자열이 이중 인용 된 경우, 당신은 같은 내부 따옴표를 이스케이프해야
? example.com/??? <- 무엇을해야합니까 ??? 있다? – Endophage이미지가 플래시 드라이브의 폴더에 있습니다. 내 HTML 파일은 한 수준 위에 있습니다. 그래서 예제는 images \ rock.jpg입니다 – user3068063
document.write (""); – way2vin