将 <a> 元素放在 document.write 中
put <a> element in document.write
我正在尝试做
document.write("<a href="http://www.google.com">Visit Google</a>");
但什么也没出现。我可以在 document.write 中不使用吗?其他 HTML 元素工作正常,例如
和 ,但这个元素什么都没有?有没有更好的链接方法?我也试过
[a link](http://www.example.com/)
但仍然没有。
不要使用 document.write()
,请改为创建一个 anchor
元素。
var a = document.createElement('a');
a.href = 'http://www.google.com'
var text = document.createTextNode('Visit Google');
a.appendChild(text);
document.body.appendChild(a);
里面有双引号,请替换它们: document.write("<a href='http://www.google.com'>Visit Google</a>");
或
document.write('<a href="http://www.google.com">Visit Google</a>');
或像下面的帖子一样转义它们:
document.write("<a href='"http://www.google.com'">Visit Google</a>");
相关文章:
- 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.innerHTML以及其他javascript问题之间有什么区别