如何禁用默认< a> “href”的行为属性? [英] How to disable default <a> behaviour of "href" attribute?
问题描述
我有一个简单侧边栏是这样的:
< DIV类= 栏 >
< ul class =nav>
< li class =Page1>< a href =Page1.html> Page1< / a>< / li>
< li class =Page2>< a href =Page2.html> Page2< / a>< / li>
< li class =Page3>< a href =Page3.html> Page3< / a>< / li>
< / ul>
< / div>
此代码存在于每个页面上:page1.html,page2.html,page3.html 。
在Page1.html上,我希望Page1不会被点击。
在Page2.html上,我希望Page2不要被点击。
在Page3.html,我想第3页不要点击。
是可以做到的,没有Javascript,即纯HTML& CSS?
如果不是的话,使用Javascript,jQuery最简单的方法是什么?
onclick =返回false
'p>上的< a取代;
要禁用标签
I have a simple sidebar like this:
<div class="sidebar">
<ul class="nav">
<li class="Page1"><a href="Page1.html">Page1</a></li>
<li class="Page2"><a href="Page2.html">Page2</a></li>
<li class="Page3"><a href="Page3.html">Page3</a></li>
</ul>
</div>
This code exist on each one of the pages: page1.html, page2.html, page3.html.
On Page1.html, I would like Page1 not to be clickable.
On Page2.html, I would like Page2 not to be clickable.
On Page3.html, I would like Page3 not to be clickable.
Is that possible to do that without Javascript, i.e. pure HTML & CSS ? If not, what would be the easiest method to do that using Javascript, jQuery ?
You could add
onclick="return false"
on the <a>
tag that you want to disable.
这篇关于如何禁用默认< a> “href”的行为属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!