【问题标题】:Javascript Submit With GetElementByID - Open in New Window使用 GetElementByID 提交 Javascript - 在新窗口中打开
【发布时间】:2012-06-10 18:30:29
【问题描述】:

我有一个名为“review.asp”的页面,其中包含一个从数据库生成记录列表的表单。如果用户想查看有关特定记录的更多信息,他们只需单击“prjName”字段,这是一个超链接。然后,页面将提交并显示有关记录的信息。目前,这在同一窗口中打开。我希望它打开一个新窗口。

此外,我不想只在 HTML 的表单部分中放置一个 target = _blank,因为此页面会进行多次提交,并且我不希望它们全部在新窗口中打开 - 只是下面的这个。所以,我希望在 Javascript 中有一个解决方案?

提前致谢!

我的 HTML:

<form name="frmPrjReview" id="frmPrjReview" method="post">
<p><a href="javascript:selectRecID('<%= RS("recID")%>')";><%=RS("prjName")%></a></p>

我当前的 Javascript:

function selectRecID(recID)
{
    //Set the value of the hidden text field = to the record ID in the table.
    document.getElementById("txtRecID").value = recID;

    var submitSearch = document.getElementById("frmPrjReview");

    submitSearch.action = "review.asp"; 
    submitSearch.submit();
}

【问题讨论】:

标签: javascript


【解决方案1】:

在需要时以编程方式设置目标:

var submitSearch = document.getElementById("frmPrjReview");
...
submitSearch.setAttribute("target", "_blank");
submitSearch.submit();
submitSearch.removeAttribute("target")

编辑:添加删除。

【讨论】:

  • ...并在您不再需要它时将其删除:submitSearch.removeAttribute("target", "_blank");
猜你喜欢
  • 2012-12-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多