2012-10-03 2 views
1

자바 스크립트 편집기를 사용하고 있으며 기본 브라우저가 작동하지만 IE 및 Firefox에서이 항목을로드 할 때 시도하지만 잘 수행되지 않습니다. 기능.InnerHTML 문이 작동하지 않는 이유를 알 수없는 것처럼 보입니다.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html> 

<head> 
<noscript> 
<p>This page requires JavaScript. Please turn on JavaScript if your browser supports it and reload the page.</p> 
</noscript> 
<script type = "text/javascript" src="jscripts/pvar.js"> 
</script> 

<title></title> 

</head> 

<body> 
<form name="form1"> 
Version 2012.10.1.1a 
<h2> 
Panasas Sizing Form 
</h2> 
<br> 
<table colspan='3' border='0'> 
<tr> 
<td align="left">&nbsp;<input type="text" name="textq1" id="dtextq1" readonly="readonly" value="How will this be sized?" style="border: 0"/> 
<select name="question1" id="dquestion1" value="" onfocus="this.style.background='khaki'" onblur="this.style.background='white'" onchange="setOptions1(document.form1.question1.options[document.form1.question1.selectedIndex].value)"> 
<Option value=""></option> 
<Option value="Capacity">Capacity</option> 
<Option value="Bandwidth">Bandwidth</option> 
<Option value="Both">Both</option> 
</select></td> 
<tr> 
<td align="left" id="q1c1">&nbsp;</td> 
<tr> 
<td align="left" id="q2c1">&nbsp;</td> 
<tr> 
<td align="left" id="q3c1">&nbsp;</td> 
<tr> 
<td align="left" id="q4c1">&nbsp;</td> 
<tr> 
<td align="left" id="q5c1">&nbsp;</td> 
<tr> 
<td align="left" id="q6c1">&nbsp;</td> 
<tr> 
<td align="left" id="q7c1">&nbsp;</td> 
</table> 
</form> 
</body> 
</html> 

자바 스크립트는 다음과 같다 :

function setOptions1(chosen) 
{ 
var label=document.getElementById; 
var textbox1=""; 
var textbox2=""; 

if (chosen == "") { 
label('q1c1').innerHTML=""; 
label('q2c1').innerHTML=""; 
label('q3c1').innerHTML=""; 
label('q4c1').innerHTML=""; 
label('q5c1').innerHTML=""; 
label('q6c1').innerHTML=""; 
label('q7c1').innerHTML=""; 

} 
if (chosen == "Capacity") { 
label('q1c1').innerHTML="How much capacity do you require?"; 
label('q1c1').appendChild(document.createTextNode(' ')); 
textbox1 = document.createElement('INPUT'); 
textbox1.type = 'text'; 
textbox1.value = 0; 
textbox1.size = 2; 
textbox1.maxLength = 4; 
label('q1c1').appendChild(textbox1); 
label('q1c1').appendChild(document.createTextNode(' ')); 
textbox2 = document.createElement('SELECT'); 
textbox2_option = document.createElement('option'); 
textbox2_option= new Option ('GB',1,true,false); 
textbox2_option= new Option ('GiB',2,false,false); 
textbox2.add(textbox2_option); 
label('q1c1').appendChild(textbox2); 
label('q2c1').innerHTML="Average File Size:"; 
label('q3c1').innerHTML="Network efficiency:"; 
label('q4c1').innerHTML="What price level?"; 
label('q5c1').innerHTML="Would you like to include an IB Router?"; 
label('q6c1').innerHTML=""; 
label('q7c1').innerHTML=""; 

} 
if (chosen == "Bandwidth") { 
label('q1c1').innerHTML="What are the bandwidth requirements?"; 
label('q2c1').innerHTML="Network efficiency:"; 
label('q3c1').innerHTML="Average File Size:"; 
label('q4c1').innerHTML="What price level?"; 
label('q5c1').innerHTML="Would you like to include an IB Router?"; 
label('q6c1').innerHTML=""; 
label('q7c1').innerHTML=""; 
} 
if (chosen == "Both") { 
label('q1c1').innerHTML="How much capacity do you require?"; 
label('q2c1').innerHTML="Average File Size:"; 
label('q3c1').innerHTML="What are the bandwidth requirements?"; 
label('q4c1').innerHTML="Network efficiency:"; 
label('q5c1').innerHTML="What price level?"; 
label('q6c1').innerHTML="Would you like to include an IB Router?"; 
label('q7c1').innerHTML=""; 
} 

}//end function 

답변

0

문제는이 라인은 다음과 같습니다

html로는

VAR 라벨 = document.getElementById를;

하는

function label(s) { 
    return document.getElementById(s); 
} 

호스트 객체로 교체가 까다 롭고 - 그들은 항상 일정한 함수 참조처럼 취급 할 좋아하지 않는다.

현재 : Google Chrome을 통해 실행 한 것보다 파일에 코드를 자르고 붙여 넣었습니다. 오류 메시지는 invalid invocation이었으며, 이는 내 첫 디버깅 단계로 label의 정의를 대체하도록했습니다.

+0

그게 전부 야 !!!!!!!! 고맙습니다!!!! – e5gf

관련 문제