If you want to do nothing after clicking a link, or respond to the click and complete other tasks, it is generally better to set the property href & quot; # & quot, the following describes several common solutions for you. If you want to create a link and click it on the webpage, you can also set the href = "#" attribute to respond to the click and complete other tasks. However, when the page has a scroll bar, the page will return to the top of the page after clicking it, poor user experience.
There are currently several solutions:
1) do not do anything after clicking the link
The Code is as follows:
Test
Test
Test // use 2 to 4 #. For details, refer to "####" and "# all ".
2) click the link to respond to user-defined click events
The Code is as follows:
Test
All problems are solved, including browser incompatibility. // or you can directly use href = ""
Test
Note:
1. javascript: the pseudo-Protocol void (0) is rarely written. If you have read some standard web books, you will know why. (Do not understand, the original words are extracted, and the record is made for now)
2. the direct use of javascript: void (0) by Link (href) in IE may cause some problems, such as: causes the GIF animation to stop playing. Therefore, the safest way is to use "####". To prevent the link from jump to the top, The onclick event return false.
3. You can use
The Code is as follows:
Click Me!
Void is a javascript operator that only executes expressions but does not return values,
The format of the void operator is as follows:
The Code is as follows:
Javascript: void (expression)
Javascript: void expression
We recommend that you use the second type with parentheses for a good program style.
We can use the void operator to specify the hyperlink, such as javascript: void (document. form. submit ()). The expression is calculated, but it does not load any content in the current document. void (0) is calculated as 0, but it has no effect on JavaScript. That is to say, the effect is the same.
The key is as long as you know that void is the operator of javascipt itself, it indicates that only expressions are executed, but no return value is returned!
In addition, the page is automatically adjusted back to the top because "#" is the top position by default, so this situation occurs.