开发者

conditional anchor tag control

开发者 https://www.devze.com 2023-03-14 18:45 出处:网络
in html, <a href=\"/shop/view-item.php\" onclick=\"checklogin(开发者_C百科);\">View Item</a>

in html,

<a href="/shop/view-item.php" onclick="checklogin(开发者_C百科);">View Item</a>

As you know, the execution order is,

1) onclick javascript function, checklogin,

2) go to href link, and page refresh, /shop/view-item.php

And if you add 'return false' in onclick function's foot, href doesn't work. so the page remain on the same page. The code is,

<a href="/shop/view-item.php" onclick="checklogin();return false;">View Item</a>

My question, Can I control 'return false' effect? If user do not log, I want to user remain the same page with alert logging request. If user logged already, let him go the anchor's link url.

Is it possible?


Make sure your checklogin() function will return true or false appropriately, then do the following:

<a href="/shop/view-item.php" onclick="return checklogin();">View Item</a>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号