HTML标签< a>想要添加href和onclick工作 [英] HTML tag <a> want to add both href and onclick working

查看:83
本文介绍了HTML标签< a>想要添加href和onclick工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想问一下HTML标记

I'd like to ask about HTML tag

<a href="www.mysite.com" onClick="javascript.function();">Item</a>

如何使 a 标签与 href onClick ? (更喜欢onClick先运行然后再href)

How to make this a tag working with href and onClick? (prefer onClick running first then href)

推荐答案



You already have what you need, with a minor syntax change:

<a href="www.mysite.com" onclick="return theFunction();">Item</a>

<script type="text/javascript">
    function theFunction () {
        // return true or false, depending on whether you want to allow the `href` property to follow through or not
    }
</script>

< a> 标记的 onclick href 属性将执行 onclick ,那么只要 onclick 不会返回 false ,请按照 href c $ c>,取消该事件(或事件未被阻止)

The default behavior of the <a> tag's onclick and href properties is to execute the onclick, then follow the href as long as the onclick doesn't return false, canceling the event (or the event hasn't been prevented)

这篇关于HTML标签&lt; a&gt;想要添加href和onclick工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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