Computer >> 컴퓨터 >  >> 프로그램 작성 >> JavaScript

JavaScript의 링크에서 href 및 target 속성을 찾는 방법은 무엇입니까?


자바스크립트 document.href를 제공했습니다. 및 document.target 링크에서 href 및 target 속성을 가져옵니다. 링크는 일반적으로

태그 및 그 내부에 href 를 포함하는 앵커 태그가 제공됩니다. 및 타겟 속성. 개별적으로 논의합시다.

href 속성 찾기

href 속성을 가져오려면 document.href 사용되어야 합니다. 다음 예에서 href 속성은 "https://www.tutorialspoint.com/"이라는 링크로 구성되며 프로그램이 실행되면 표시됩니다.

예시

<html>
<body>
<p><a id="myId" href="https://www.tutorialspoint.com/">tutorialspoint</a></p>
<script>
   var ref = document.getElementById("myId").href;
   document.write(ref);
</script>
</body>
</html>

출력

tutorialspoint

https://www.tutorialspoint.com/


대상 속성 찾기

대상 을 얻으려면 속성, document.target 사용되어야 합니다. 다음 예에서 대상 속성 "_union "가 프로그램 실행 시 표시되었습니다.

예시

<html>
<body>
<p><a id="myId" target="_union" href="https://www.tutorialspoint.com/">tutorialspoint</a></p>
<script>
   var ref = document.getElementById("myId").target;
   document.write(ref);
</script>
</body>
</html>

출력

tutorialspoint

_union