问题描述
我的页面上有一组可点击的标识符.大约有一百个,例如"cat1","cat2","dog1","dog2","dog3"等.然后我有一个function IDClick(id) {}
I have a set of clickable identifiers on my page. About hundred, like 'cat1', 'cat2', 'dog1', 'dog2', 'dog3' etc. Then I have a function IDClick(id) {}
我需要那些可在HTML中单击的标识符,以实现将<a>
标记与onclick
一起使用
I need those identifiers clickable in HTML, to achieve that I used <a>
tag with onclick
<a onclick=IDClick(id)>id</a>
现在可以正常工作,但是将鼠标悬停在可点击元素上时,光标不会改变.
now it works, but the cursor will not change when it is hovered over the clickable element.
所以我尝试添加href=#
<a href=# onclick=IDClick(id)>id</a>
现在光标可以了,但是当我单击该项目时,浏览器位置栏中的URL将会更改.这是不希望的.
Now the cursor is OK, but when I click the item, the URL in the browser location bar will change. This is not desired.
如何获得混合行为?
我也不需要加下划线.
推荐答案
您可以使用CSS强制光标在clickable元素悬停时进行更改:
You can use CSS to force the cursor to change on hover of the clickable element:
.myClickableThingy {
cursor: pointer;
}
然后您可以切换回<span>
或<a>
标记之前使用的任何元素.
And then you can switch back to <span>
s or whatever of element you were using before <a>
tags.
这篇关于建立具有onclick但没有href =#的可点击链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!