Is there any reason to use one of the following more than the others:
<input type="button" value="b1" onclick="manageClick(this)" />
<input type="button" value="b2" onclick="manageClick(this);" />
<input type="button" value="b2" onclick="manageClick(this);return false;" />
<input type="button" value="b3" onclick="return manageClick(this);" />
<input type="button" value="b4" onclick="javascript:return manageClick(this);" />
And please do not spend your valuable time to tell me to use jQuery or attachEvent
/addEventListener
. It's not really the objective of my question.
There's no difference at all between the first two, in this specific situation the semicolon is optional.
The third one will prevent any default action from occurring, which the first two won't.
The fourth will prevent the default action or not depending on the return value of manageClick
.
The fifth one is incorrect.
(And wherever suitable, use attachEvent
/addEventListener
-- ducks and runs)
<input type="button" value="b3" onclick="return manageClick(this);" />
edit Return is preferable in cases where you wish to control element behaviour, such as for <a>
and <input type="submit">
, so assuming this is the case, above is your answer, if not just omit the return and just go with onclick="manageClick(this);"
.
Also, have a look at http://crisp.tweakblogs.net/blog/313/the-useless-javascript-pseudo-protocol.html regarding the use of javascript:
. ^_^
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With