JavaScript: Using document.write();
JavaScript: Using document.write();
我试图在JavaScript中使用document.write
INSIDE另一个document.write
创建一个新的HTML文档。
我知道这是一种痛苦的方法(并且可以随意重写代码以获得所需的输出),但是这里是:
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();
如您所见,按钮没有清楚地输出信息。我不知道我做错了什么
需要进行大量转义:
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();
问题开始了:
</p><button onclick='"var newDoc = document.open('"text/html'"
^^ starting onclick ^^ ending it
var newDoc = document.open("text/html", "replace");
newDoc.write("<html><head><title>Failure!</title></head><body>Button:<button onclick='"var newDoc = document.open("text/html", "replace"); newDoc.write("<html><head><title>Double Fail</title></head><body><p>Button clicked.</p></body></html>"); newDoc.close();'">Continue</button></body></html>");
newDoc.close();
你的报价很差。生成的HTML将在"
上中断,您需要在onclick
属性中使用HTML转义("
),而不是JavaScript转义('"
)。
相关文章:
- document.open/document.write没有正确地清除chrome中的文档——这是chrome的错误吗
- 如何用更合适的内容替换document.write
- 在document.write中包含javascript的原因
- 仅对标题标记的一部分使用document.write
- Javascript:使用document.write时删除子项
- 如何在一个网页网站中处理基于document.write()的广告标签
- Javascript 使用 document.write 编写 innerHtml 的值
- 在Chrome中,如何知道document.write何时更改iframe的内容
- 如何在使用函数document.write()打印最终结果后,使用Javascript滚动到页面顶部
- 具有javascript document.write的响应图像
- document.write()覆盖整个页面
- Firefox中document.write()的树不平衡
- document.write未返回字符串
- Javascript的“document.write()”中的PHP代码
- 为什么我需要使用 document.write 而不是 DOM 操作方法
- 使用document.write()在页面上显示图像
- 无法运行php函数来使用document.write更新db值
- document.write asynchronous (JavaScript)
- Javascript Age Document.write,帮助打印18岁及以上和50岁及以上的语句
- 为什么两个“document.write(document.links[i].href)”"是错误的