admin管理员组

文章数量:1392050

I try to prevent page reload when user click a link, so I wrote :

<a href="javascript: return false">bla</a>

Or

<a href="#">bla</a>

Seriously I don't like to use # because when user click on the link, the url on the address bar is added the symbol #, it make the url look ugly. So I prefer to use javascript: return false but firebug show error : "return not in function", may I know how to fix the error?

I try to prevent page reload when user click a link, so I wrote :

<a href="javascript: return false">bla</a>

Or

<a href="#">bla</a>

Seriously I don't like to use # because when user click on the link, the url on the address bar is added the symbol #, it make the url look ugly. So I prefer to use javascript: return false but firebug show error : "return not in function", may I know how to fix the error?

Share Improve this question asked Jun 1, 2011 at 1:01 zac1987zac1987 2,7879 gold badges47 silver badges62 bronze badges 2
  • :-) not exactly. on clicking the link nothing will happen then why he need the href!!! i was inspired by sprynos answer :-) – zod Commented Jun 1, 2011 at 1:15
  • lol. Very creative, but I need onclick attribute. – zac1987 Commented Jun 1, 2011 at 1:25
Add a ment  | 

3 Answers 3

Reset to default 6

See this discussion: Which "href" value should I use for JavaScript links, "#" or "javascript:void(0)"?

Do not use href="#". If it has to be, either use "javascript:;" or "javascript:void(0);"

Try using this instead:

<a href="javascript:;">bla</a>

Hope that helps.

Look at this (jsfiddle here):

<a href="http://www.google./" onclick="return false;">click me</a>

However, you should avoid using inline JavaScript. The JS in one place, separated from the code, has higher maintainability.

本文标签: javascriptHow to fix quotreturn not in functionquot error that shown on firebugStack Overflow