href=“#”与href=“javascript:void(0)”区别
使用过ajax的都常见这样的代码:
<a href="javascript:doTest2();void(0);" mce_href="javascript:doTest2();void(0);">here</a>
但这儿的void(0)究竟是何含义呢?
Javascript中void是一个操作符,该操作符指定要计算一个表达式但是不返回值。
void 操作符用法格式如下:
1. javascript:void (expression)
2. javascript:void expression
expression 是一个要计算的 Javascript 标准的表达式。表达式外侧的圆括号是选的,但是写上去是一个好习惯。 (实现版本 Navigator 3.0 )
你以使用 void 操作符指定超级链接。表达式会被计算但是不会当前文档处装入任何内容。
下面的代码创建了一个超级链接,当用户以后不会发生任何事。当用户链接时,void(0) 计算为 0,但 Javascript 上没有任何效果。
<A HREF="javascript:void(0)" mce_HREF="javascript:void(0)">单此处什么也不会发生</A>
下面的代码创建了一个超级链接,用户单时会提交表单。
<A HREF="javascript:void(document.form.submit())" mce_HREF="javascript:void(document.form.submit())">
单此处提交表单</A>
a href=#与 a href=javascript:void(0) 的区别 链接的几种办法
#包含了一个位置信息
默认的锚是#top 也就是网页的上端
而javascript:void(0) 仅仅表示一个死链接
这就是为什么有的时候页面很长浏览链接明明是#是
跳动到了页首
而javascript:void(0) 则不是如此
所以调用脚本的时候最好用void(0)
或者<input onclick>
<div onclick>等
链接的几种办法
1.window.open(’’url’’)
2.用自定义函数
<mce:script type="text/javascript"><!--
function openWin(tag,obj)
{
obj.target="_blank";
obj.href = "Web/Substation/Substation.aspx?stationno="+tag;
obj.click();
}
// --></mce:script>
<a href="javascript:void(0)" mce_href="javascript:void(0)" onclick="openWin(3,this)">株洲</a>
window.location.href=""
Tags:href=“#”与hre
相关文档:
Use the Fast Parts 使用速度快的部分
Even though JavaScript is often blamed for being slow, there are parts of the language that are incredibly fast. This should come as no surprise, since JavaScript engines are built in lower-level languages and are therefore compiled. Thou ......
JavaScript Minification JavaScript紧凑
JavaScript minification is the process by which a JavaScript file is stripped of everything that does not contribute to its execution. This includes comments and unnecessary whitespace. The process typically reduces the file size by ha ......
Working Around Caching Issues 关于缓存问题
Adequate cache control can really enhance the user experience, but it has a downside: when revving up your application, you want to make sure your users get the latest version of the static content. This is accomplished by renaming ......
由于火狐浏览器不支持“removeNode”函数,所以一下代码只支持IE.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
< ......
JavaScript是基于对象的,任何元素都可以看成对象。然而,类型和对象是不同的。本文中,我们除了讨论类型和对象的一些特点之外,更重要的是研究如何写出好的并且利于重用的类型。毕竟,JavaScript这种流行的脚本语言如果能够进行良好的封装,并形成一个庞大的类型库,对于重用是非常有意义的。
网上对于prototype的文章很 ......