Java脚本如何在禁用后重新启用超链接 [英] Java script How to enable the Hyperlink back after disableing

查看:57
本文介绍了Java脚本如何在禁用后重新启用超链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





在我的代码中,我最初启用了Hyper链接,在一种情况下使用此代码禁用超链接



  var  onclickEvents; 
function disableHyperlinks(){
onclickEvents = Array ();
var anchors = document .getElementsByClassName( hyper);
for var i = 0 ; i< anchors.length; i ++){
onclickEvents.push(anchors [i] .onclick);
anchors [i]。 önclick= function (){ return false ; };
}

}





禁用超链接正常工作。



之后的另一个条件我想启用超链接,使用下面的代码



< pre lang =Javascript> function enableHyperlinks(){
if (onclickEvents!= < span class =code-keyword> null ){
var anchors = document .getElementsByClassName( hyper);
for var i = 0 ; i< anchors.length; i ++){
anchors [i]。 önclick= onclickEvents [i];
}
}
}





上面的代码工作不正常我做错了。



我想重新启用链接。



在禁用时返回false



总是它返回false并且超链接无法启用。



请帮帮我。

解决方案

根据您的需要修改代码。

 < script     type   =  text / javascript >  
function disable_link(){
document.getElementById(' testlink')。disabled = true ;

document.getElementById(' testlink')。removeAttribute(' href');
}
function enable_link(){
document.getElementById(' testlink').setAttribute( href,link);
}
< / script >





来源: http://stackoverflow.com/questions/13174201/disable-enable-a-hyperlink-by-clicking-on-radio-buttons [ ^ ]


Hi,

In my code I have Hyper links initially they are enabled, in one condition am disabling the hyperlinks using this code

var onclickEvents;
       function disableHyperlinks() {
           onclickEvents = Array();
           var anchors = document.getElementsByClassName("hyper");
           for (var i = 0; i < anchors.length; i++) {
               onclickEvents.push(anchors[i].onclick);
               anchors[i]. önclick = function() { return false; };
                      }

       }



disabling of the hyper links working fine.

after that another condition I want to enable the hyper links for that am using the code below

function enableHyperlinks() {
            if (onclickEvents != null) {
                var anchors = document.getElementsByClassName("hyper");
                for (var i = 0; i < anchors.length; i++) {
                    anchors[i]. önclick = onclickEvents[i];
                }
            }
        }



Above code is not working fine am doing any mistake.

I want to re-enable the links.

while doing disabling it returns false

always it taking returns false and the hyper links not enabling.

Help me please.

解决方案

Modify code according to your needs.

<script type="text/javascript">
        function disable_link() {
            document.getElementById('testlink').disabled = true;

            document.getElementById('testlink').removeAttribute('href');
        } 
        function enable_link() {
            document.getElementById('testlink').setAttribute("href", link);
        }
</script>



Source : http://stackoverflow.com/questions/13174201/disable-enable-a-hyperlink-by-clicking-on-radio-buttons[^]


这篇关于Java脚本如何在禁用后重新启用超链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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