js
JS - anchors 객체
anchors 객체는 문서에 존재하는 <a name=""> 형식의 모든 앵커를 배열에 담습니다.
이제 새로운 앵커를 만들어 보겠습니다.
document.anchors.속성
메서드 | 설 명 |
---|---|
anchors | 문서에 존재하는 모든 앵커를 배열에 담습니다.
|
anchor | 새로운 앵커를 만듭니다. |
<a name="php">샵(#)</a><br/>
<a name="asp">구글</a><br/>
<!-- name 속성이 없어서 거짓 -->
<a href="#">naver</a><br/>
<!-- name 속성이 없어서 거짓 -->
<a href="http://habonyphp.com:2082">하보니 PHP</a><br/>
<script>
var anc = document.anchors;
for(var i = 0; i < anc.length; i++) {
document.write( anc[i].name + " (" + anc[i].text + ")<br/>");
}
/*
결과
php (샵(#))
asp (구글)
*/
</script>
이제 새로운 앵커를 만들어 보겠습니다.
<script>
var txt = "문자열";
document.write( txt.anchor("title") );
/*
결과
<a name="title">문자열</a>
*/
</script>
0 댓글