`
hsyzijvaa
  • 浏览: 107351 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

<a/>中href和onclick的区别

    博客分类:
  • java
阅读更多
    <ol style="line-height: 1.4em; margin: 0px 0px 1.5em; font-size: 1em; padding: 0px;"><li style="margin: 0px 0px 0.25em 30px; font-size: 1em; padding: 0px;">[size=small;]链接的 <code style="font-family: 'courier new', courier, monospace; white-space: pre; font-size: 1em;">onclick</code> 事件被先执行,其次是 <code style="font-family: 'courier new', courier, monospace; white-space: pre; font-size: 1em;">href</code> 属性下的动作(页面跳转,或 javascript 伪链接);[/size]</li><li style="margin: 0px 0px 0.25em 30px; font-size: 1em; padding: 0px;">[size=small;]假设链接中同时存在 <code style="font-family: 'courier new', courier, monospace; white-space: pre; font-size: 1em;">href</code> 与 <code style="font-family: 'courier new', courier, monospace; white-space: pre; font-size: 1em;">onclick</code>,如果想让 <code style="font-family: 'courier new', courier, monospace; white-space: pre; font-size: 1em;">href</code> 属性下的动作不执行,<code style="font-family: 'courier new', courier, monospace; white-space: pre; font-size: 1em;">onclick</code> 必须得到一个 <code style="font-family: 'courier new', courier, monospace; white-space: pre; font-size: 1em;">false</code> 的返回值。[/size]</li><li style="margin: 0px 0px 0.25em 30px; font-size: 1em; padding: 0px;">[size=small;]如果页面过长有滚动条,且希望通过链接的 <code style="font-family: 'courier new', courier, monospace; white-space: pre; font-size: 1em;">onclick</code> 事件执行操作。应将它的 <code style="font-family: 'courier new', courier, monospace; white-space: pre; font-size: 1em;">href</code> 属性设为 <code style="font-family: 'courier new', courier, monospace; white-space: pre; font-size: 1em;">javascript:void(0);</code>,而不要是 <code style="font-family: 'courier new', courier, monospace; white-space: pre; font-size: 1em;">#</code>,这可以防止不必要的页面跳动;[/size]</li><li style="margin: 0px 0px 0.25em 30px; font-size: 1em; padding: 0px;">[size=small;]如果在链接的 <code style="font-family: 'courier new', courier, monospace; white-space: pre; font-size: 1em;">href</code> 属性中调用一个有返回值的函数,当前页面的内容将被此函数的返回值代替;[/size]</li><li style="margin: 0px 0px 0.25em 30px; font-size: 1em; padding: 0px;">[size=small;]在按住shift键的情况下会有所区别。[/size]</li><li style="margin: 0px 0px 0.25em 30px; font-size: 1em; padding: 0px;">[size=small;]今天我遇到的问题,在ie6.0里以href的形式访问不到parentnode。[/size]</li><li style="margin: 0px 0px 0.25em 30px; font-size: 1em; padding: 0px;">[size=small;]尽量不要用javascript:协议做为a的href属性,这样不仅会导致不必要的触发window.onbeforeunload事件,在ie里面更会使gif动画图片停止播放。[/size]</li><li style="margin: 0px 0px 0.25em 30px; font-size: 1em; padding: 0px;">[size=small;]<span style="color: #ff0000;">调用js时候对参数的处理方式不一致,href会将url编码的内容自动转码,例如%22将会转成",从而导致被"%22"出现js错误。[/size]</span></li></ol>
<html>	<head>		<script type="text/javascript">		<!--		function handler1(arg1){			alert(arg1);		}		-->		</script>	</head>	<body>		<table width="155">		<tr>			<td>			<div style="height:195;width:157px;overflow:auto;border:1px solid #999999;">			   <table width="155" border="0" cellspacing="0" cellpadding="0" id="datatable">				<tr>					<a onclick="javascript:handler1('%22%5b%40', 'y', 'n', 'sam report');">test</a>.				</tr>				<tr>					<a href="javascript:handler1('%22%5b%40', 'y', 'n', 'sam report');">test1</a>				</tr>				   </table>			</div>			</td>		</tr>		</table>	</body></html>
 
0
1
分享到:
评论

相关推荐

    快餐栏:该存储库用于显示警报消息

    link rel =" stylesheet " href =" css/snackbar.css " type =" text/css " /&gt; &lt;/ head &gt; &lt; body &gt; &lt; button type =" button " onclick =" showSnackbar() " &gt; &lt;/ button &gt; &lt; script...

    HTML中button标签点击实现页面跳转的三种方法

    方法1:使用onclick事件 &lt;input type=button value=按钮 onclick=javascrtpt:[removed].href='http://www.baidu.com/' /&gt;  或者直接使用button标签 &lt;button onclick=[removed].href = '...&lt;/a&gt;

    lhgcalendar时间插件demo

    &lt;head&gt; &lt;base href &quot;&lt;% basePath%&gt;&quot;&gt; &lt;title&gt;My JSP &quot;MyJsp jsp&quot; starting page&lt; title&gt; &lt;script type &quot;text javascript&quot; src &quot;&lt;%...

    js实现按钮开关单机下拉菜单效果

    通过onclick单击事件,实现效果,代码如下: &lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;meta charset=utf-8&gt; &lt;title&gt;开关按钮设置&lt;/title&gt; &lt;/head&gt; &lt;link rel=stylesheet ...

    Asp+AJAX静态分页 亲测 可用

    /a&gt;'; } function save() { //保存修改后的显示条数 var pagesize=document.getElementById('pagesize'); //这个就不写了,跟上面的用法一样。 if (pagesize.value==''||/[0-9]+/.test(pagesize.value)==false...

    JavaScript计算器网页版实现代码分享

    JavaScript网页计算器代码,该计算器是用DW写的!...link href="style/calculator.css" rel="stylesheet" type="text/css" /&gt; [removed][removed]&gt; &lt;/head&gt; &lt;body &gt; &lt;form id="form1" name="f

    JS传参及动态修改页面布局

    link rel=stylesheet href=css/style.css rel=external nofollow /&gt; &lt;/head&gt; &lt;body&gt; &lt;div id=button&gt;&lt;h1&gt;请为下面的DIV设置样式:&lt;/h1&gt;点击设置&lt;/div&gt;&lt;/div&gt; &lt;div class=s

    javascript实现点击单选按钮链接转向对应网址的方法

    这里实现一个按钮特效,当点击复选择框按钮的时候,激活链接,跳转到某网址,这里主要是由onClick派生出来的一些功能,然后配合函数你可以编写出更多的按钮特效来。 运行效果截图如下: 具体代码如下: &lt;...

    javascript实例分享—具有立体效果的图片特效

    此实例是我一遍学习一边写出来的,希望能够帮到大家,一起学习。效果如图所示: ... 代码如下:&lt;...link rel=”stylesheet” type=”text/css” href = “style/css.css”&gt; &lt;/head&gt; &lt;b

    JS动态添加的div点击跳转到另一页面实现代码

    obj.onclick=function(){ [removed].href=跳转的地址 rel=external nofollow ; } 源文件: &lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;首页推荐页面&lt;/title&gt; &lt;meta name=author ...

    Flash插件本地下载

    1.&lt;html&gt; 2.&lt;body&gt; 3. 4. //SysDownloadFlashFashion等于0时就是本地下载 5. if(SysDownloadFlashFashion==0){%&gt; 6. ;cursor:pointer;" align="center"&gt; 7. 正在检测插件 &lt;br&gt;&lt;/div&gt; 8. ; ...

    javascript实现类似超链接的效果

    实现类似超链接的效果,this代表本页面元素 代码如下: &lt;html&gt; &lt;head&gt; [removed] function mOver(obj){ ...onclick=”[removed].href=’http://www.baidu.com/'” onmouseover=”mOver

    javascript动态添加删除tabs标签的方法

    LINK href="style.css" type=text/css rel=stylesheet&gt; [removed] function $(obj) { var o = typeof(obj)=="object" ? obj : document.getElementById(obj); return o; } function addChannel(ChannelId,Label...

    UBB编辑器

    &lt;!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN” “‘ target=_blank rel=nofollow&gt;...link href=”style.css” rel=”stylesheet” type=”text/css”&gt;&lt;script lang

    moon-heightmaps-256p-ne

    input type = button onclick = [removed].href =' '; value ='您现在处于GitHub网页视图中-单击此处以查看自述文件作为源代码'/&gt; 该存储库包含10,800个PNG,这些PNG为月球提供0至60度和0至180度经纬度的高度图...

    简易js代码实现计算器操作

    link rel=”stylesheet” type=”text/css” href=””&gt; &lt;meta http-equiv=”content-type” content=”text/html;charset=utf-8″&gt; &lt;!–js代码可以放置在任意位置,按照先后顺序依次执行 一般放在head...

    openlayers-map-marker:使用openlayers地图创建标记。 带有弹出窗口,地图多边形,地图事件的地图标记

    具有Openlayers 6.3的地图标记 使用openlayers地图创建标记,使用弹出窗口创建简单的地图标记。 ... &lt; head &gt; &lt; link rel =" stylesheet " href... link href =" map.css " rel =" stylesheet " &gt; &lt; scri

    JS实现iframe编辑器光标位置插入内容的方法(兼容IE和Firefox)

    本文实例讲述了JS实现iframe编辑器光标...input type="button" onclick="frames['x'].location.href='about:blank';" value="clear"&gt; [removed] //setTimeout('window.frames["x"].document.designMode="On"',200);

    js实现的捐赠管理完整实例

    本文实例讲述了js捐赠管理完整实现方法。分享给大家供大家参考。具体实现方法如下: ... 代码如下:&lt;!...&lt;html xmlns=”...link href=”css/css.css” rel=”Stylesheet” type=”text/css”

    克隆,回复

    //$("."+className+":last "+".exist "+"input").attr("onclick","change("+data.lists[i].PRIMARY_ID+")"); $("."+"ans"+":last "+"textarea").text(data.lists[i].REPLY_MESSAGE); $("."+"ans"+":last ")....

Global site tag (gtag.js) - Google Analytics