HTML标记<a>希望同时添加href和onclick工作
我想问一下HTML标签
<a href="www.mysite.com" onClick="javascript.function();">Item</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 ,只要onclick不返回false ,取消事件(或事件未被阻止) 
 使用[jQuery] [1]。 您需要捕获click事件,然后进入网站。 
 $("#myHref").on('click', function() { alert("inside onclick"); window.location = "http://www.google.com"; }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <a href="#" id="myHref">Click me</a>