2016-04-28 56 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>