f

출력 결과가 이상하게 다르네요....

안녕하세요.
자바스크립트 초보라 이렇게 질문 드립니다.
 
동일한 내용을 출력하는데 함수에서 호출 할 경우와 그렇지 않을 경우의 결과가 다릅니다.
왜 그런가요?
 
 
[예제1]
<html>
<head>
<script type="text/javascript">
function print_form()
{
 document.write(document.forms.length);
 document.write(document.forms[0].elements[1].name);
}
</script>
</head>
<body>
<form>
name:<input type="text" name="name" /><br />
phone:<input type="text" name="phone" /><br />
</form>
<form>
name2:<input type="text" name="name2" /><br />
phone2:<input type="text" name="phone2" /><br />
</form>
<input type="submit" onclick="print_form()" />

</body>
</html>
 
결과 : 2, name 이 정상 출력 되어야 하는데 이상하게 2만 출력이 되네요.
 
[예제2]
<html>
<head>
</head>
<body>
<form>
name:<input type="text" name="name" /><br />
phone:<input type="text" name="phone" /><br />
</form>
<form>
name2:<input type="text" name="name2" /><br />
phone2:<input type="text" name="phone2" /><br />
</form>
<script type="text/javascript">
document.write(document.forms.length);
document.write(document.forms[0].elements[0].name);
</script>

</body>
</html>
 
결과 : 2, name 이 정상 출력 됩니다.
|

댓글 3개

document.write(document.forms.length+document.forms[0].elements[1].name); 요렇게 처리해야 할듯 싶내요...
새로운 페이지가 생성되면서 잃으면서 다음건 출력 안되는거내요.
도통 모르겠네요
일단은 두 페이지가 소스가 다르네요

document.forms[0].elements[0].name
document.forms[0].elements[1].name

http://math88.com.ne.kr/computer/js/JSmanual/7-2-6-2.html
댓글을 작성하시려면 로그인이 필요합니다.

프로그램

+
제목 글쓴이 날짜 조회
14년 전 조회 1,633
14년 전 조회 1,999
14년 전 조회 1,754
14년 전 조회 1,900
14년 전 조회 2,276
14년 전 조회 1,760
14년 전 조회 2,134
14년 전 조회 1,710
14년 전 조회 1,671
14년 전 조회 2,275
14년 전 조회 4,161
14년 전 조회 1,727
14년 전 조회 3,138
14년 전 조회 1,927
14년 전 조회 1,814
14년 전 조회 2,697
14년 전 조회 2,630
14년 전 조회 1,599
14년 전 조회 2,509
14년 전 조회 2,963
14년 전 조회 2,381
14년 전 조회 1,613
14년 전 조회 3,014
14년 전 조회 1,810
14년 전 조회 1,588
14년 전 조회 1,554
14년 전 조회 2,279
14년 전 조회 2,649
14년 전 조회 2,142
14년 전 조회 1,617
14년 전 조회 1,795
14년 전 조회 2,317
14년 전 조회 2,270
14년 전 조회 1,581
14년 전 조회 4,361
14년 전 조회 2,273
14년 전 조회 5,444
14년 전 조회 1,815
14년 전 조회 2,831
14년 전 조회 1,893
14년 전 조회 1,772
14년 전 조회 2,656
14년 전 조회 1,679
14년 전 조회 2,626
14년 전 조회 1,731
14년 전 조회 2,432
14년 전 조회 2,014
14년 전 조회 5,016
14년 전 조회 2,998
14년 전 조회 1,836
14년 전 조회 1,752
14년 전 조회 2,277
14년 전 조회 1,960
14년 전 조회 1,984
14년 전 조회 3,167
14년 전 조회 1,703
14년 전 조회 3,917
14년 전 조회 3,791
14년 전 조회 2,147
14년 전 조회 1,843
14년 전 조회 3,243
14년 전 조회 1,973
14년 전 조회 2,200
14년 전 조회 1,622
14년 전 조회 2,730
14년 전 조회 2,155
14년 전 조회 2,234
14년 전 조회 2,517
14년 전 조회 1,657
14년 전 조회 4,731
14년 전 조회 1,900
14년 전 조회 2,818
14년 전 조회 2,238
14년 전 조회 1,716
14년 전 조회 5,684
14년 전 조회 1,571
14년 전 조회 3,692
14년 전 조회 1,927
14년 전 조회 1,688
14년 전 조회 2,093
14년 전 조회 8,809
14년 전 조회 2,010
14년 전 조회 3,062
14년 전 조회 2,508
14년 전 조회 2,066
14년 전 조회 5,143
14년 전 조회 1,755
14년 전 조회 2,202
14년 전 조회 1,775
14년 전 조회 1,809
14년 전 조회 2,608
14년 전 조회 3,402
14년 전 조회 1,878
14년 전 조회 2,058
14년 전 조회 1,990
14년 전 조회 2,255
14년 전 조회 1,501
14년 전 조회 2,047
14년 전 조회 1,582
14년 전 조회 1,946