2014-07-22 4 views
-3

라디오 버튼 인 HTMl 문서와 외부 파일 filename.js 에있는 기능이 있으며 내부를 사용하고 있습니다. 올바른 방법으로 올바른 방법으로 책에서 고양이를 복사하지만, html 파일을 실행하면 작동하지 않습니다. .html 파일과 filename.js 파일을 새 폴더에 두 개만 넣습니다. 여기에 문제가있는 것 같아서, 나는 약간의 제안을 좋아한다.외부 파일의 자바 스크립트 배치

authorx.

+1

처럼 보인다? – Mike

+0

일부 코드 샘플을 게시하십시오 –

답변

0

일부 코드를 보지 않고도 정확하게 말할 수는 없지만 HTML 파일에서 별도의 javascript 파일을 실행하는 표준 방법은 script 태그를 사용하는 것입니다. 여기에 더 많은 정보 : 귀하의 경우 http://www.w3schools.com/tags/tag_script.asp

이 태그는

<script src="filename.js"></script> 
-1

내 코드 같이 보일 것입니다 당신이뿐만 아니라 몇 가지 코드를 게시 할 수있는이

<!DOCTYPE html> 
<html lang="en"> 
<head> 
<meta charset="utf-8" /> 
<title> Radio Button </title> 
<script type= "text/javascript" src = "radio_plane.js" > 
</script> 

<body> 
<h4> Cessna single-engine airplane description </h4> 
<form id="myform" action=""> 
<p> 
<label><input type="radio" name="planebutton" value="152" onclick="action(152);" /> 
       Model 152 </label> 
       <br /> 
<label><input type="radio" name="planebutton" value="172" onclick="action(172);" /> 
       Model 172 (Skyhawk)</label> 
      <br /> 
<label><input type="radio" name="planebutton" value="182" onclick="action(182);" /> 
       Model 182</label> 
      <br /> 
<label><input type="radio" name="planebutton" value="210" onclick="action(210);" /> 
      Model 210 (Centurian) </label> 
      <br /> 
</p> 
</form> 

</body> 
</html> 
and javascript file 


function action(plane) 
{ 
switch(plane) 
{ 
case 152: 
alert("A small two-place airplane for flight training"); 
break; 
case 172: 
alert("The Smaller of two four-plane airplanes"); 
break; 
case 182: 
alert("The larger of two four-place airplanes"); 
break; 
case 210: 
alert("A six-place high-performance airplane"); 
break; 
default: 
alert("Error in JavaScript function planeChoice"); 
break; 
} 
} 
+0

코드 샘플은 별도의 대답이 아닌 원래 질문으로 작성되어야합니다. 이 코드를 포함하도록 원래 질문을 수정하십시오. – Ectropy

관련 문제