如何在单击按钮时弹出页面

How to popup a page when a button is on click?

本文关键字:按钮 单击      更新时间:2023-09-26

我希望在按下按钮时在弹出窗口中打开一个新页面。这是我到目前为止的代码:

<td><input type="button" name="to" value="" style="height:24px; width:24px; background:url('addressbook.png'); border:none; onClick="myPopup()""> To:</td> 
<script type="text/javascript">
function myPopup() 
{
  window.open( "http://www.google.com/" )
}
</script>

当我按下时,它失败了。我按下时没有弹出窗口...我认为我写的代码不正确,但我不确定。我需要你的帮助。

<html>
<body>
<p>Click the button to open a new window with some specifications.</p>
<button onclick="myFunction()">Try it</button>
<script>
function myFunction() {
    window.open("http://www.google.com", "_blank", "toolbar=yes, scrollbars=yes, resizable=yes, top=500, left=500, width=400, height=400");
}
</script>
</body>
</html>

您已将onclick添加到 style 属性。 看起来只是不匹配的引号。 更改此设置:

style="height:24px; width:24px; background:url('addressbook.png'); border:none; onClick="myPopup()""

对此:

style="height:24px; width:24px; background:url('addressbook.png'); border:none;" onClick="myPopup()"

您没有关闭 Style 标记,而是在点击后放置了它的 "。

这应该有效

<td><input type="button" name="to" value="" 
style="height:24px; width:24px; background:url('addressbook.png'); border:none;"
onClick="myPopup()"> To:</td> 
<script type="text/javascript">
function myPopup() 
{
  window.open( "http://www.google.com/" )
}
</script>