我想问一下关于HTML标签的事
<a href="www.mysite.com" onClick="javascript.function();">Item</a>
如何使这个a标签与href和onClick一起工作?(首选先运行onclick,然后运行href)
我想问一下关于HTML标签的事
<a href="www.mysite.com" onClick="javascript.function();">Item</a>
如何使这个a标签与href和onClick一起工作?(首选先运行onclick,然后运行href)
您已经有了所需的内容,只需稍作语法更改:
<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
,然后跟随href
,只要onclick
没有返回false
,就取消事件(或者事件没有被阻止)