使用js与<a>两种方式
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gbk" /> <title>锚点</title> </head> <mce:script type="text/javascript"><!-- function go(){ window.location.hash="m2" return false; } // --></mce:script> <body> <a href="#" mce_href="#" onclick="return go()" >跳到2</a> <a href="#m3" mce_href="#m3">跳到3</a> <a href="test.html#m3" mce_href="test.html#m3">跳到test.html#m3</a> <p>start...<p> <div style="margin-top:500px" mce_style="margin-top:500px"> <p id="m2">hello m2!</p> helloWorld! </div> <div style="margin-top:500px" mce_style="margin-top:500px"> <p><a name="m3"></a>hello m3</p> </div> <div style="padding-top:1000px" mce_style="padding-top:1000px"></div> </body> </html>
test.html:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gbk" /> <title>锚点</title> </head> <body> <p>11111111<p> <div style="margin-top:500px" mce_style="margin-top:500px"> <p id="m2">helloWorld!</p> helloWorld! </div> <div style="margin-top:500px" mce_style="margin-top:500px"> <p><a name="m3"></a>test.html:helloWorld!</p> </div> <div style="padding-top:1000px" mce_style="padding-top:1000px"></div> </body> </html>