我想在document.write()的javascript文件中發佈圖像。問題是,當我嘗試它時,圖像總是出現斷裂。這是代碼。我是否寫錯了標籤?我已經在非javascript頁面上測試過這些圖片,並且它們看起來很好。使用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