2013-02-13 4 views
-1

글쎄, 자바 스크립트에 익숙하지 않았습니다. C++에서 C# VB를 완성했습니다. 그러나이 자바 스크립트 책은 이해하기 어렵습니다. 아무 것도 아니지만 살펴볼 전체 코드는 없습니다. 어쨌든 나는 간단한 프로젝트를하고 있지만 어디서 잘못 될지 이해하지 못한다. CDATA는 제가 잘못 될 것이라고 믿습니다. 이것은 내 두 번째 프로젝트이며 첫 번째 작업은 CDATA와 Var가 나올 때까지 쉽지 않았습니다. 나는이 코드가 구식임을 알고 있지만, 기본적인 JS를 배우고 내 방식대로 작업하기 위해 책을 따라 가고있다. Heres는 코드 :자바 스크립트에서 CDATA에 문제가 있습니다.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
    <html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<title>Largest Islands</title> 
<meta http-equiv="content-type" content="text/html; charset=iso- 
8859-1" /> 
</head> 
<body> 
<h1>Largest Islands</h1> 
<script type="text/javascript"> 
/* <![CDATA[ */ 
var island1Name = "Greenland"; 
var island2Name = "New Guinea"; 
var island3Name = "Borneo"; 
var island4Name = "Madagascar"; 
var island5Name = "Baffin"; 
var island1Size = 2175600; 
var island2Size = 790000; 
var island3Size = 737000; 
var island4Size = 587000; 
var island5Size = 507000; 
document.write("<p>The largest island 
in the world is " + island1Name 
+ " with " + island1Size + " miles.</p>"); 
document.write("<p>The second largest island 
in the world is " + island2Name 
+ " with " + island2Size + " miles.</p>"); 
document.write("<p>The third largest island 
in the world is " + island3Name 
+ " with " + island3Size + " miles.</p>"); 
document.write("<p>The fourth largest island 
in the world is " + island4Name 
+ " with " + island4Size + " miles.</p>"); 
document.write("<p>The fifth largest island 
in the world is " + island5Name 
+ " with " + island5Size + " miles.</p>"); 
/* ]]> */ 
</script> 
</body> 
</html> 

의 난 그냥 내가 잘못 가고있는 곳을 파악하는 도움을 필요로하는 매우 간단한 프로젝트. 사전에 감사합니다.

+1

아니요, 아니요, CDATA가 잘못 될 곳이 아닙니다. 그것은 무엇을해야 하는가? 그게 옳은 일이 아닌가? 오류가 있습니까? – ceejayoz

+0

그럼 작동하지 않는 것은 무엇입니까? – Bergi

답변

0

여기에 줄 바꿈이라고 생각합니다. 귀하의 코드 :

document.write("<p>The largest island 
in the world is " + island1Name 
+ " with " + island1Size + " miles.</p>"); 

가되어야한다

document.write("<p>The largest island in the world is " + island1Name 
+ " with " + island1Size + " miles.</p>"); 

당신이 라인에 문자열을 시작하고 같은에 끝나지 않는 경우가 라인 원인이 오류를 던지고 휴식 것입니다. 게다가 파이어 폭스를 개발할 때 파이어 버그와 함께 스크립트를 디버깅 할 것을 제안합니다.

0

로컬에서 실행하면 JavaScript 오류 콘솔에서 문제가있는 곳을 분명히 알 수 있습니다. 그것은 심지어 줄 번호를 제공합니다.

document.write("<p>The largest island 
in the world is " + island1Name... 

JavaScript 문자열 중간에 줄 바꿈을 사용할 수 없습니다.

document.write("<p>The largest island in the world is " + island1Name... 

작품입니다. 이 모든 것을 수정하고 모든 주요 브라우저에서 사용할 수있는 개발 도구를 사용하기 시작해야합니다.

0

나는 문제가 시도 깨는 캐릭터 라인 대신

document.write("<p>The largest island 
in the world is " + island1Name 

에서 오는 생각

document.write("<p>The largest island" 
+ "in the world is " + island1Name 
0

귀하의 문제가이 같은 여러 줄 문자열을 자바 스크립트에서 허용되지 않는 것을 :

document.write("<p>The second largest island 
in the world is " + island2Name 

잘못된 곳에서 새 줄을 제거하면 코드가 작동합니다. 그 선이 지금과 같을 것이다 :

document.write("<p>The second largest island in the world is " + island2Name 

예 : http://jsbin.com/igowel/1/edit

자바 스크립트 작업을 계속하려면, 콘솔 및 개발자 도구를 사용하여 익숙해. Chrome의 경우이 Q를 & A : How do I use the JavaScript Console in Google Chrome?

+0

감사합니다. 그 책은 나에게 거기에 휴식을 넣어라고했기 때문에 그것은 이상합니다. – user2069296

+0

솔직히 말해서, 그것은 정말 오래된 책처럼 보입니다. 바닐라 자바 ​​스크립트로 시작하는 것이 좋지만, 시작하기 전에 jQuery와 같은 것이 정말 편리합니다.2 ~ 3 년이 넘는 책이라면 jQuery in Action과 같은 최신 도서를 받아 볼 수 있습니다 (실제로는 어쨌든 제안 할 것입니다). – Cymen

관련 문제