void The void operator returns undefined for any value. This is typically used to avoid outputting a value that shouldn’t be output, such as when calling a JavaScript function from an HTML <a> element. To do this properly, the function cannot return a valid value; otherwise the browser erases the page and displays only the result of the function. For example: <a href=”javascript:window.open(‘about:blank’)”>Click Me</a> If you place this line of code into an HTML page, and click the link, you see “[Object]” printed on the screen (Figure 2-3). This occurs because window.open() returns a reference to the newly opened window (this and other methods of the window are discussed further in Chapter 5, “JavaScript in the Browser”). That object is then converted to a string for display. To avoid this, use the window.open() call with the void operator: <a href=”javascript:void(window.open(‘about:blank’))”>Click Me</a> This makes the window.open() call return undefined, which is not a valid value and is not displayed in the browser window. Remember, functions that have no return value actually return undefined.说下,主要是说如果href属性有返回值,brower就会erase 当前页面,并显示返回值 ,可以用返回值undefined来阻止这种默认行为, void(window.open)返回undefined
http://www.w3school.com.cn/js/pro_js_operators_unary.asp教程
<a href="#“> 或<a href="javascript:;">区别是空锚点会引起页面返回顶部,而javascript; javascript:void(0),不会引起页面返回顶部
为了是消除点击事件后的 A 标签默认的跳转事件
也可以使用<a href="#" onclick="openWin(3,this);return false;">XXXXX</a>代替
以上方式通过事件中的 return false;来阻止元素默认事件的执行,我觉得从可用性和可读性上比<a href="javascript:void(0)" onclick="openWin(3,this)">php自学网</a>好
如果换成#号,在本地文件夹中打开后点击链接,会打开当前文件夹。在应用服务器中http方式打开的
会是当前页面,有些浏览器会连接到当前页面,相当于刷新一次。有些则无然后操作
<a href="javascript:void(0)">
<a href="javascript:return fasle;">效果类似
void
The void operator returns undefined for any value. This is typically used to avoid outputting a value
that shouldn’t be output, such as when calling a JavaScript function from an HTML <a> element. To do
this properly, the function cannot return a valid value; otherwise the browser erases the page and displays
only the result of the function. For example:
<a href=”javascript:window.open(‘about:blank’)”>Click Me</a>
If you place this line of code into an HTML page, and click the link, you see “[Object]” printed on the
screen (Figure 2-3). This occurs because window.open() returns a reference to the newly opened window
(this and other methods of the window are discussed further in Chapter 5, “JavaScript in the
Browser”). That object is then converted to a string for display.
To avoid this, use the window.open() call with the void operator:
<a href=”javascript:void(window.open(‘about:blank’))”>Click Me</a>
This makes the window.open() call return undefined, which is not a valid value and is not displayed
in the browser window. Remember, functions that have no return value actually return undefined.说下,主要是说如果href属性有返回值,brower就会erase 当前页面,并显示返回值
,可以用返回值undefined来阻止这种默认行为,
void(window.open)返回undefined