gpt4 book ai didi

javascript - window.open() 在 JS 函数中无法正常工作

转载 作者:行者123 更新时间:2023-12-03 05:59:36 24 4
gpt4 key购买 nike

我尝试为我的网站创建一个更新列表,这样当我单击相关更新时,将打开一个新的附加小 html 窗口,我将看到完整的更新内容。
这是我写的代码:

index.html:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<script type="text/javascript" src="script.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
</head>

<body ng-app="myApp">

<p ng-controller="updatesCtrl">
<span ng-repeat="x in updates">
<a href="updateWindow.html" onclick="showUpdate(x.title,x.update)">&#9679; {{x.title}}</a>
<br><br>
</span>
</p>

<script>updates();</script>

</body>
</html>

脚本.js:

function updates(){
angular.module('myApp', []).controller('updatesCtrl', function($scope) {
$scope.updates = [
{title:"update1",update:"update1 content"},
{title:"update2",update:"update2 content"}
];
});
}

function showUpdate(title, update){
var win=window.open('updateWindow.html','newwindow','width=600, height=350');
win.document.getElementById("title").innerHTML=title;
win.document.getElementById("update").innerHTML=update;
return false;
}

更新窗口.html:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
</head>
<body>

<h1 id="title"></h1>
<p id="update"></p>

</body>
</html>

我这里有一些问题:
1.当我点击更新链接时,更新窗口取代了主页(index.html)窗口,并且也是全尺寸页面。
2.<h1>中没有进行任何更改和 <p> updateWindow 的 - 尽管我编写了一个脚本,该脚本应该在这些地方输入 html 内容。

我不明白为什么我没有通过这段代码得到我所期望的结果。特别是,我不明白第一个问题:如果我只尝试替换 onclick里面的内容index.html与此:"window.open('updateWindow.html','newwindow','width=600, height=350'); return false;" - 我得到一个新的附加窗口,其尺寸符合预期(我不会在该窗口内获得更新内容,但至少解决了我的第一个问题)。

我的代码有什么问题?

最佳答案

尝试使用 window.open('updateWindow.html','_blank','width=600, height=350'); 代替

关于javascript - window.open() 在 JS 函数中无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39801009/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com