앵커 수를 얻으려면 앵커를 사용하세요. 재산.
예시
다음 코드를 실행하여 JavaScript로 앵커 수를 얻을 수 있습니다. -
<!DOCTYPE html>
<html>
<body>
<a href="https://www.tutorialspoint.com/php" name="PHP">PHP</a>
<br>
<a href="https://www.tutorialspoint.com/java/" name="Java">Java</a>
<br>
<a href="https://www.tutorialspoint.com/html5/" name="HTML5">HTML</a>
<br>
<a href="https://www.tutorialspoint.com/css/" name="CSS">CSS</a>
<script>
var val = document.anchors.length;
document.write("<br>Number of anchors in the document: "+val);
</script>
</body>
</html>