JavaScript为字符串对象创建锚|String Anchor() 方法

JavaScript String 对象


定义与用法

anchor() 方法用于创建 HTML 锚。

该方法返回加了 <a> 标签的字符串, 如下所示:

<a name=”anchorname”>string</a>


语法格式

string.anchor(name)


浏览器支持

方法Google ChromeInternet ExplorerFirefoxSafariOpera
Anchor()YesYesYesYesYes

所有主要浏览器都支持 anchor() 方法。


参数说明

参数描述
name必须,锚文本的名字。

示例代码

创建 HTML 锚:

<script> 
    var txt = "Chapter 10"; 
    txt.anchor("chap10"); 
    alert(txt.anchor("chap10")); 
</script>

亲自试试


JavaScript String 对象


相关