When making a page, if you want to do nothing after clicking a link, or complete other things in response to the click, you can set its attribute href = "#". However, there will be a problem when the page has a scroll bar. , it will return to the top of the page after clicking, which is a bad user experience.
There are currently several solutions:
1) Do nothing after clicking the link
test test test //Use 2 to 4 #, most of them are "####", but also " #all" and others
2) After clicking the link, respond to the user-defined click event
Explanation:
1.javascript:void(0) This pseudo Protocols should be written less. If you have read some web standards books, you will know why. (I don’t understand, I’m excerpting the original words, so I’ll record them temporarily)
2. Directly using javascript:void(0) for links (href) may cause some problems in IE, such as causing the gif animation to stop playing, etc., so, The safest way is to use "####". To prevent jumping to the top of the page after clicking the link, the onclick event can return false.
3. If you just want to move the mouse over and turn it into a hand shape, you can use
Click Me!
void is the operator of javascript, It means: only the expression is executed, but there is no return value. The
void operator usage format is as follows:
javascript:void (expression)
javascript:void expression
For good program style, it is recommended to use the second type of
with brackets We can use the void operator to specify a hyperlink, such as javascript:void(document.form.submit()). The expression will be evaluated but nothing will be loaded into the current document. void(0) evaluates to 0 but has no effect on JavaScript, i.e.
.
The key is to know that void is the operator of javascipt itself. It means that only the expression is executed, but there is no return value!
In addition, the page will automatically move back to the top because the default aiming point position of "#" is top, so this happens.