- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<a href="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="<a href="http://www.w3.org/1999/xhtml">http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <title>JS阻止链接跳转</title>
- </head>
- <body>
- <div align="center">
- <table width="300" height="100" border="0" cellpadding="0" cellspacing="0" bgcolor="#66CCFF">
- <tr>
- <td align="center"><a href="<a href="http://www.CodeSnippet.Cn">http://www.CodeSnippet.Cn" id="testLink">点击此链接</a>
- <script type="text/javascript">var test = document.getElementById('testLink');
- test.onclick = function(e) {
- alert('链接地址是:' + this.href + ', 不过不会直接跳转');
- stopDefault(e);
- }
- </script></td>
- </tr>
- </table>
- </div>
- </body>
- </html>
- //该片段来自于http://www.codesnippet.cn/detail/110120131564.html
来源: http://www.codesnippet.cn/detail/110120131564.html