HTML anchor tag with Javascript onclick event

对着背影说爱祢 提交于 2019-11-27 18:54:52
TJHeuvel

If your onclick function returns false the default browser behaviour is cancelled. As such:

<a href='http://www.google.com' onclick='return check()'>check</a>

<script type='text/javascript'>

function check()
{
    return false;
}

</script>

Either way, whether google does it or not isn't of much importance. It's cleaner to bind your onclick functions within javascript - this way you separate your HTML from other code.

You can even try below option:

<a href="javascript:show_more_menu();">More >>></a>
Aditya Manohar

From what I understand you do not want to redirect when the link is clicked. You can do :

<a href='javascript:;' onclick='show_more_menu();'>More ></a>

Use following code to show menu instead go to href addres

function show_more_menu(e) {
  if(!confirm('Do you want to go to: '+e.target.href)) e.preventDefault();;
}
<a href='more.php' onclick="show_more_menu(event)"> More >>> </a>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!