如何使用JavaScript禁用li标签 [英] how to disable a li tag using JavaScript

查看:154
本文介绍了如何使用JavaScript禁用li标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的网页上使用以下HTML:

I am using the following HTML on my page:

<ul id="tabnav">

        <li id="tab_a" class="tab1"><a href="tab1.htm">Tab a</a></li>
        <li id="tab_b" class="tab2"><a href="tab2.htm">Tab b</a></li>
        <li id="tab_c" class="tab3"><a href="tab3.htm">Tab c</a></li>
    </ul>

我想做的是让你不能点击第三个标签javascript然后我希望以后可以点击第三个标签。

What I am trying to do is make it so that you can't click on the 3rd tab using javascript then I want to be able to click on the 3rd tab at a later time.

所以我尝试在JavaScript函数中使用以下JavaScript:

So I have tried using the following JavaScript in a JavaScript function:

document.getElementById("tab_c").style.enabled = false;

但它似乎不起作用。

我希望它会被禁用,所以你不能点击它。

I was hoping that it would make it disabled so you can't click on it.

我做错了什么?

推荐答案

您可以向返回false的链接添加onclick处理程序。

You can add an onclick handler to the link that returns false.

document.getElementById("tab_c").childNodes[0].onclick = function() {return false;};​

childNodes [0] 只选择第一个孩子,在这种情况下是< a> ;

The childNodes[0] just selects the first child which in this case is the <a>

例如 http://jsfiddle.net/zYSeF/

这篇关于如何使用JavaScript禁用li标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆