id与name实现锚点链接

锚点链接
本页面内跳转

1、使用id

 <a id="line1_name">the first line</a>
 <a href='#line1_name'><button>Go first line</button></a>

2、使用name

<a name="line1_name">the first line</a>
<a href='#line1_name'><button>Go first line</button></a>
其他页面之间跳转

目的页面代码与上相同,要用页面代码如下

<a href='要跳到的文件名.html#line1_name'><button>Go that page</button></a>
我的案例

本页面

<!doctype html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>anchor</title>
</head>
<body>
	<!-- id的 -->
	<a id="line1_name">the first line.</a><br/>
	<!-- name的,选其一即可 -->
	<a name="line1_name">the first line.</a><br/>
</body>
</html>
<script type="text/javascript">
	for(var i=0;i<=100;i++){
		document.write("I am a study!<br/>");
	}
	for(var i=0;i<=0;i++){
		document.write("<a href='#line1_name'><button>Go first line</button></a><br/>");
	}
</script>

其他页面

<!doctype html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>anchor</title>
</head>
<body>
</body>
</html>
<script type="text/javascript">
	for(var i=0;i<=0;i++){
		document.write("<a href='锚点链接.html#line1_name'><button>Go that page</button></a><br/>");
	}
</script>
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值