我正在做一個令人難以置信的基本JavaScript練習,用於練習Objects的學校。我認爲普通的document.write可以工作,但它不會,我查了許多地方,但很多地方只是用於控制檯。 錯誤是如何將Javascript對象寫入文檔。在'文檔'上執行'寫入'失敗
無法在'文檔'上執行'寫':除非明確打開,否則無法從異步加載的外部腳本寫入文檔。
如果有人可以幫助這將是巨大的,對不起,如果它真的很容易
這裏是我的代碼
var oPerson = {
firstName: 'John',
lastName: 'Travis',
gender: 'Male',
age: 22,
district: 'Northshore',
hairColor: 'Brown',
hairLength: 'Short',
height: '6\'11"',
weight: '74kg',
martialStatus: 'Engaged'
}
document.write(oPerson);
document.write(oPerson.district);
oPerson.resident = "yes";
document.write(oPerson);
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Exercise - Personal Info</title>
<script src="practice9JS.js" type="text/javascript"></script>
</head>
<body>
</body>
</html>
你的代碼工作 – sheplu
需要顯示對象的內容作爲一個整體,以及 – Dale
那麼是什麼所有人都在談論'無法執行「寫」上「Document''?問題是錯誤還是錯誤輸出?由於錯誤,我的意思是「不是你所期望的」,因爲打印的內容對你寫的代碼是正確的。 – csmckelvey