void:
该操作符指定要计算一个表达式但是不返回函数值
语法格式:
<head>
<script type="text/javascript">
<!--
void func()
javascript:void func()
或者
void(func())
javascript:void(func())
//-->
</script>
</head>
例如:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<a
href="javascript:void(0)">单此处什么也不会发生
</a>
</body>
</html>
<head>
<script type="text/javascript">
<!--
function getValue(){
var a,b,c;
a = void ( b = 5, c = 7 );
//a=void(0); b=5; c=7;
document.write('a = ' + a + ' b = ' + b +' c = ' + c );
}
//-->
</script>
</head>
运行结果:
a = undefined b = 5 c = 7
href=”#”与href=”javascript:void(0)”的区别:
包含了一个位置信息,默认的锚#top也就是网页的上端。而Javascript:void(0),仅仅是表示一个死链接。在页面很长的时候会使用#来定位页面的具体位置,格式为:#+id。如果你要定义一个死链接请使用Javascript:void(0)。
<a href="javascript:void(0);">点我没有反应的!</a>
<a href="#pos">点我定位到指定位置!</a>
<br>
...
<br>
<p id="pos">尾部定位点</p>