js
JS - links 객체
links 객체는 문서에 존재하는 <a href=""> 형식의 태그를 배열에 담습니다.
이제 새로운 링크를 만들어 보겠습니다.
document.links.속성
메서드 | 설 명 |
---|---|
links | 문서에 존재하는 모든 <a>링크를 배열에 담습니다.
|
link | 새로운 링크를 만듭니다. |
<a href="php">샵(#)</a><br/>
<a href="#" target="_blank">naver</a><br/>
<a href="http://habonyphp.com:2082">하보니 PHP</a><br/>
<script>
var link = document.links;
for(var i = 0; i < link.length; i++) {
document.write( link[i].href + " [" + link[i].target +"]<br/>");
}
/*
결과
http://localhost:8080/php []
http://localhost:8080/# [_blank]
http://habonyphp.com:2082/ []
*/
</script>
이제 새로운 링크를 만들어 보겠습니다.
<script>
var str = "하보니 php";
document.write( str.link("http://habonyphp.com") );
// <a href="http://habonyphp.com">하보니 php</a>
</script>
0 댓글