如何确认在href标签中的链接导航? [英] How to confirm navigation for a link in a href tag?

查看:87
本文介绍了如何确认在href标签中的链接导航?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为管理控制台使用简单链接,但如果用户意外点击链接以删除用户,应该会弹出一个确认弹出窗口。

I'm using simple links for an admin panel but in case of user accidently clicks on link for user deletion, there should be a confirmation pop-up for avoding this.

可能你知道一个href标签与javascript不完全兼容。所以,我已经使用了span标记来实现onclick,但是效果并不理想:

Probably as you know a href tag's are not fully compatible with javascript. So, i have used span tag for "onclick" but that didn't went so well:

<script type="text/javascript">
function confirm_click()
{
return confirm("Are you sure ?");
}

</script>

以下是链接的html代码:

Here is the html code for link:

   <span onclick="confirm_click();">    <a title="Delete User" href="http://www.google.com"><i class="icon-remove-sign">DELETE</i></a></span>


推荐答案

尝试...

Try...

<a title="Delete User" onclick="return confirm_click();" href="http://www.google.com"><i class="icon-remove-sign">DELETE</i></a>

...改为。

您需要返回方法的值,并且在onclick事件中返回false可以防止默认行为(在这种情况下,这将导航到href)。

You need to return the value of your method, and returning false in an onclick event prevents the default behaviour (which in this case would be to navigate to the href).

这篇关于如何确认在href标签中的链接导航?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆