【问题标题】:Document.write JavasScript [duplicate]Document.write Javascript [重复]
【发布时间】:2014-07-16 00:19:48
【问题描述】:

如何将此document.write 代码的第一部分转换为弹出链接?请注意第一部分说"<a href=\"\/popups\/fed_budget.asp\"><img src=\"http:\/images\/video_graphic.jpg\ 等。如何将该按钮链接 (video_graphic.jpg) 更改为弹出窗口,而不是将我带到不同的页面?这是我目前拥有的:

document.write("<td width=\"251px\"><a href=\"\/popups\/fed_budget.asp\"><img src=\"http:\/images\/video_graphic.jpg\" alt=\"Video Graphic\" \/><\/a><\/td>");
document.write("<td style=\"padding-top:30px; padding-left:10px; padding-right:10px\">");

document.write("<b class=\"blue_text\">Recent News<\/b><br \/><br \/>");
document.write("<strong><a    href=\"\/news\/newshub\/articles\/federal_budget_2014.asp\">Your Federal Budget Update<\/a>  <\/strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b class=\"blue_text\">New<\/b><br    \/>");

document.write("Read our run-down on the super side of this year's Budget.<br \/><br   \/><br \/>");
document.write("<strong><a href=\"\/news\/newshub\/articles\/EOFY_Tips_tricks.asp\">EOFY tips and tricks<\/a><\/strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b class=\"blue_text\">New<\/b><br \/>");
document.write("Six strategies to help you get your super in shape.<br \/><br \/>");
document.write("<\/td>");
document.write("<\/tr>");
document.write("<\/table>");

【问题讨论】:

  • 从不使用document.write开始,如果在文档最初加载后调用它会覆盖文档,完全不推荐。请改用 appendChild、innerHTML 等 DOM 方法。

标签: javascript frontend document.write


【解决方案1】:

如果在另一个窗口中打开链接就是您所说的“弹出”,那么您最简单的做法是在链接中添加一个target 属性,所以它看起来像这样:

<a href="/popups/fed_budget.asp" target="_blank"><img src="http://images/video_graphic.jpg" alt="Video Graphic"/></a>

如果您想在简化的新窗口中打开它,则必须使用调用 window.open 的 JavaScript 点击处理程序:

<a href="#" onclick="window.open('/popups/fed_budget.asp')">...</a>

哦,我会模仿整个“永远不要使用 document.write”的理念。

【讨论】:

    【解决方案2】:

    弹出链接?您的意思是在新标签页中打开它吗?

    只需将属性target="_blank" 添加到a 标记即可。

    类似:

    <a target="_blank" href="..."><img src="..." /></a>
    


    Ps.:避免使用document.write

    target=“_blank” vs. target=“_new”
    HTML <a> target Attribute

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-06-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多