Home  >  Article  >  Web Front-end  >  javascript anchor() 方法创建 HTML 锚

javascript anchor() 方法创建 HTML 锚

WBOY
WBOYOriginal
2016-06-01 09:54:381642browse

anchor 方法在对象中的指定文本两端放置一个有 NAME 属性的 HTML 锚点。

基本语法:

<code class="language-javascript">strVariable.anchor(anchorString)</code>

参数介绍

参数 描述
anchorString 必需。想放在 HTML 锚点的 NAME 属性中的文本。

实例:

调用 anchor 方法来在 String 对象外创建一个命名的锚点。

下面示例说明了 anchor 方法是如何实现这个的:

<code class="language-javascript"><script type="text/javascript">
var strVariable = "This is an anchor" ;
strVariable = strVariable.anchor("Anchor1");
alert(strVariable);
</script></code>

在线运行

执行完最后一条语句后 strVariable 的值为:

<code class="language-html"><a name="Anchor1">This is an anchor</a></code>

 

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn