HTML DOM ancre collection
Définition et utilisation
Il renvoie une collection de tous les ancres hyperliens tableau page en cours.
grammaire
document.anchors[].property
support du navigateur
Tous les principaux navigateurs prennent en charge la collecte des ancres
Exemples
exemple 1
Retourne le nombre de documents liés:
<! DOCTYPE html>
<Html>
<Head>
<Meta charset = "utf-8">
<Titre> Ce tutoriel (w3big.com) </ title>
</ Head>
<Body>
<a name="html"> HTML tutoriel </a> <br>
<a name="css"> CSS tutoriel </a> <br>
<a name="xml"> XML tutoriel </a> <br>
<a href="/js/"> tutoriel JavaScript </a>
<P> Nombre d'ancres:
<Script>
document.write (document.anchors.length);
</ Script> </ p>
</ Body>
</ Html>
<Html>
<Head>
<Meta charset = "utf-8">
<Titre> Ce tutoriel (w3big.com) </ title>
</ Head>
<Body>
<a name="html"> HTML tutoriel </a> <br>
<a name="css"> CSS tutoriel </a> <br>
<a name="xml"> XML tutoriel </a> <br>
<a href="/js/"> tutoriel JavaScript </a>
<P> Nombre d'ancres:
<Script>
document.write (document.anchors.length);
</ Script> </ p>
</ Body>
</ Html>
Des exemples de sortie ci-dessus:
锚的数量: 3
Essayez »
exemple 2
Retour au document dans le premier texte d'ancre de lien:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>本教程(w3big.com)</title>
</head>
<body>
<a name="html">HTML 教程</a><br>
<a name="css">CSS 教程</a><br>
<a name="xml">XML 教程</a>
<p>文档中第一个锚:
<script>
document.write(document.anchors[0].innerHTML);
</script>
</p>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>本教程(w3big.com)</title>
</head>
<body>
<a name="html">HTML 教程</a><br>
<a name="css">CSS 教程</a><br>
<a name="xml">XML 教程</a>
<p>文档中第一个锚:
<script>
document.write(document.anchors[0].innerHTML);
</script>
</p>
</body>
</html>
Des exemples de sortie ci-dessus:
文档中第一个锚: HTML 教程
Essayez »
Document Object