我試圖在JavaScript中使用document.write
內部另一個document.write
創建一個新的HTML文檔。JavaScript:使用document.write();
我知道這是一個痛苦的方式做到這一點(和隨意改寫與期望輸出的代碼),但在這裏它是:
var newDoc = document.open("text/html", "replace");
newDoc.write("<html><head><title>Failure!</title></head><body><h5>js::error 5015 &&syn.0</h5><p>In Quantum Mechanisms exists a quantum state known as quantum superposition - the state of being two things at once given a random subatomic event that may or may not occur.</p><p>A famous experiment by Erwin Schrödinger, a cat was placed in a box along with a poison flask that would kill the cat, only activating if a subatomic change was detected (which is completely random). The thought experiment brought forth the idea of the cat being <em>dead</em> and <em>alive</em> at the same exact time, but you aren't able to know which it is. So in theory, by opening the box and finding that the cat is dead, you have essentially killed the cat yourself.</p><p>Quantum Mechanics have been applied to the button you just clicked. The choice was yours on whether or not to click it, and you did not know where you would end up. You can say that it would have unlocked a new upgrade, or break the game, but since you clicked the button, you therefore must have broken the game yourself. Just like that, curiosity killed the cat. Sorry, quantum superposition is pretty terrible. Fortunately, you can click this button below to continue on your journey.</p><button onclick=\"var newDoc = document.open(\"text/html\", \"replace\"); newDoc.write(\"<html><head><title>Double Fail</title></head><body><p>No seriously, quantum mechanics are pretty bad. :)</p></body></html>\"); newDoc.close();\">Continue</button></body></html>");
newDoc.close();
正如你所看到的,該按鈕不清楚輸出信息。不知道我做錯了什麼。
文件撰寫的折舊,不再受現代開發人員使用。使用DOM操作來添加和刪除元素。 –
什麼意思? –
有沒有什麼特別的原因讓你甚至要一次使用'document.write',更不用說兩次了? – Amadan