<FRAMESET COLS="*,*" ONLOAD="selectFrames()" ONUNLOAD="alert('stopped')"
<FRAME SRC = "frames/grey.htm" NAME="firstFrame">
</FRAMESET>
<script language="javascript">
function selectFrames(){
base="frame/"
newFrames = new Array("red.htm","blue.htm","pink.htm","grey.htm")
window.firstFrame.location = base+newFrames[Math.round(5*Math.random())%5]
window.secondFrame.location = base+newFrames[Math.round(5*Math.random())%5]
}
它是灰色的简单设置框,但是我不知道为什么代码不起作用。设置了控制台错误,属性位置未定义,任何人都可以向我介绍现有代码的位置。
最佳答案
<FRAMESET COLS="*,*" ONLOAD="selectFrames()" ONUNLOAD="alert('stopped')">
<FRAME SRC = "frames/grey.htm" NAME="firstFrame">
<FRAME SRC = "frames/blue.htm" NAME="secondFrame">
</FRAMESET>
<script>
function selectFrames(){
var bs = "frames/",
newFrames = ["red.htm","blue.htm","pink.htm","grey.htm"];
window.frames['firstFrame'].location.href = bs + newFrames[Math.round(Math.random()*5)];
window.frames['secondFrame'].location.href = bs + newFrames[Math.round(Math.random()*5)];
}
</script>
要跟踪语法错误,请在您的头上添加以下代码:
<head><script>
"use strict";
window.onerror = function(msg, url, line){
alert(unescape(msg) + '\nFile: <a href="' + url + '">' + url + '</a>\nat Line: ' + line);
}
</script></head>
关于javascript - JavaScript中的框架,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36911652/