<li id="Account_Tab" class="bgrad">
<a class="bganch" title="Accounts Tab" href="/xxx/xxx">Accounts</a>
</li>
类似方式的其他标签很少<li>,我如何为锚标签创建onclick功能,
不喜欢:<a onclick="function()"......>除了内联 Javascript,还有其他方法吗?
<li id="Account_Tab" class="bgrad">
<a class="bganch" title="Accounts Tab" href="/xxx/xxx">Accounts</a>
</li>
类似方式的其他标签很少<li>,我如何为锚标签创建onclick功能,
不喜欢:<a onclick="function()"......>除了内联 Javascript,还有其他方法吗?
您可以像这样添加处理程序:
function anchorClicked(){
console.log("clicked");
}
window.onload = function(){
var anchors = document.getElementsByClassName('bganch');
for(var i=0; i<anchors.length; i++){
anchors[i].onclick = anchorClicked;
}
};
上面将 click 事件添加到具有bganch该类的元素中。
其他选项:
document.getElementById('someid')document.getElementsByTagName('a')尝试
window.onload = function(){
var anchors = document.getElementsByClassName('bganch');
var anchortitle= anchors.title;
};