[PHP]html - <a>태그 <a href=”javascript:”>

2015. 1. 6. 17:29FrontEnd/Web



336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

<a href=”javascript:”>

 

An <a> element is invalid HTML unless it has either an href or name attribute.

If you want it to render correctly as a link (ie underlined, hand pointer, etc), then it will only do so if it has a href attribute.

Code like this is therefore sometimes used as a way of making a link, but without having to provide an actual URL in the href attribute. The developer obviously wanted the link itself not to do anything, and this was the easiest way he knew.

He probably has some javascript event code elsewhere which is triggered when the link is clicked, and that will be what he wants to actually happen, but he wants it to look like a normal <a> tag link.

Some developers use href='#' for the same purpose, but this causes the browser to jump to the top of the page, which may not be wanted. And he couldn't simply leave the href blank, because href=''is a link back to the current page (ie it causes a page refresh).

There are ways around these things. Using an empty bit of Javascript code in the href is one of them, and although it isn't the best solution, it does work.


stackoverflow 댓글....

'FrontEnd > Web' 카테고리의 다른 글

jquery selectbox  (0) 2015.01.22
[mysql] DB 백업 / db backup  (0) 2015.01.08
[PHP] ini_set  (0) 2014.12.30
mysql 원격접속이 안될때.  (0) 2014.10.28
php이클립스  (0) 2014.10.23