2016-04-28 79 views
0
<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] 
} 

框架在JavaScript

其在灰色布提简单的设置框架不知道这是为什么代码不能正常工作。控制台错误设置属性位置未定义任何人都可以指导我对现有代码的位置。

回答

0

你缺少右括号您<FRAMESET标签:

<FRAMESET COLS="*,*" ONLOAD="selectFrames()" ONUNLOAD="alert('stopped')" 

应该是:

<FRAMESET COLS="*,*" ONLOAD="selectFrames()" ONUNLOAD="alert('stopped')"> 

你也会从你的JavaScript线路末端缺少分号。

+0

哈哈三江源非常 –

+0

没有问题:)请注明所接受,如果它是正确的。 – Alfie

1
<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>