some link My main doub...">

Javascript protocol and events

What does the following code mean:

<a href="javacsript:;" onClick="addItem(160)">some link</a>

My main doubt is that the script runs when we click on the link

+5
source share
5 answers

Will be executed first onclick. If it onclickdoes not return false(in this case it is not), then it hrefwill be processed.

+3
source

Part of javascriptthe attribute hrefis the protocol (you know, for example, http, ftp or mailto). What it does is tell the browser that the URL is actually JavaScript code.

, , , href. , onclick , href. , onclick .

, , , true () false ().

, , , addItem. false, . true, href. (.. ), .

:

<a href="http://google.com/" onclick="return false;">won't go to google.com</a>
<a href="http://google.com/" onclick="return true;">will go to google.com</a>

?

+2

!, "function addItem (x)" javascript, script . ( )

0

"javascript:" href - javascript .

, , "".

<a href="javascript:alert('testing');">Click me</a>

javascript,

<a href="javacsript:;">Click me</a>

Onclick - , . href, ; javascript.

onclick, href. URL- ( href URL-, ), , javascript.

"javascript:;" "javascript: void (null);" href , onclick.

; , href script .

0

, "javascript:" "href", , , <a>! :

http://gutfullofbeer.net/jslink.html

( , ) :

<a href='javascript:getLink()'>Click to go there!</a>

"getLink()" :

  function getLink() {
    var sel = document.getElementById('sel');
    return sel.options[sel.selectedIndex].value;
  }

, <select> , . <select>?

<select id='sel'>
  <option value='<html><head><meta http-equiv="refresh" content="2;http://cnn.com"/></head><body>Redirecting to CNN ...</body></html>'>CNN</option>

  <option value='<html><head><meta http-equiv="refresh" content="2;http://zombo.com"/><head><body>Redirecting to Zombocom ...</body></html>'>Zombocom</option>
  <option value='<html><head><meta http-equiv="refresh" content="2;http://reddit.com"/></head><body>Redirecting to Reddit ...</body></html>'>Reddit</option>
</select>

- HTML . URL- , .

. , - .

0

All Articles