javascript void
javascript:void(0) Meaning
We often use code like javascript:void(0), so in JavaScript javascript:void What does (0) mean?
The most critical thing in javascript:void(0) is the void keyword. void is a very important keyword in JavaScript. This operator specifies to calculate an expression but does not return a value.
##The syntax format is as follows:
< ;head>The following code creates a hyperlink that does nothing when the user clicks on it.<script type="text/javascript">
<!--
void func()
javascript:void func()
or
void(func())
javascript:void(func())
//-->
</script>
</head>
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php中文网(php.cn)</title> </head> <body> <a href="javascript:void(0)">单此处什么也不会发生</a> </body> </html>When the user links, void(0) evaluates to 0, but has no effect on Javascript. In the following example, a warning message is displayed after the user clicks the link:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>php中文网(php.cn)</title>
<script type="text/javascript">
<!--
//-->
</script>
</head>
<body>
<p>点击以下链接查看结果:</p>
<a href="javascript:void(alert('Warning!!!'))">点我!</a>
</body>
</html>Run the program and try itIn the following example, parameter a will return undefined:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>php中文网(php.cn)</title>
<script type="text/javascript">
function getValue(){
var a,b,c;
a = void ( b = 5, c = 7 );
document.write('a = ' + a + ' b = ' + b +' c = ' + c );
}
</script>
</head>
<body>
<p>点击以下按钮查看结果:</p>
<form>
<input type="button" value="点我" onclick="getValue();" />
</form>
</body>
</html>Run the program and try itThe difference between href="//m.sbmmt.com/global/code/#" and href="javascript:void(0)"
# Contains With a location information, the default anchor is #top, which is the top of the web page. And javascript:void(0) only represents a dead link. When the page is very long, # will be used to locate the specific location of the page. The format is: # + id. If you want to define a dead link, please use javascript:void(0).Example
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php中文网(php.cn)</title> </head> <body> <a href="javascript:void(0);">点我没有反应的!</a><br/> <a href="#pos">点我定位到指定位置!</a> <br> ... <br> <p id="pos">尾部定位点</p> </body> </html>Run the program and try it
new file
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>php中文网(php.cn)</title>
<script type="text/javascript">
<!--
//-->
</script>
</head>
<body>
<p>点击以下链接查看结果:</p>
<a href='javascript:alert("Warning!!!");'>点我!</a>
</body>
</html>
Preview
Clear
- Course Recommendations
- Courseware download
The courseware is not available for download at the moment. The staff is currently organizing it. Please pay more attention to this course in the future~
Students who have watched this course are also learning
Let's briefly talk about starting a business in PHP
Quick introduction to web front-end development
Large-scale practical Tianlongbabu development of Mini version MVC framework imitating the encyclopedia website of embarrassing things
Getting Started with PHP Practical Development: PHP Quick Creation [Small Business Forum]
Login verification and classic message board
Computer network knowledge collection
Quick Start Node.JS Full Version
The front-end course that understands you best: HTML5/CSS3/ES6/NPM/Vue/...[Original]
Write your own PHP MVC framework (40 chapters in depth/big details/must read for newbies to advance)
















