繁体   English   中英

禁用Div“按钮”,然后启用

[英]Disable Div “Button” and then enable

我试图在页面加载时“ disablediv ,然后几秒钟enable它。 我想要的效果是使onclick返回false几秒钟,并且不透明度低。 计时器启动后,我希望不透明度返回到1并且onclick设置为将window.location.href设置为proceed.html的函数。 它基本上是一个禁用几秒钟的按钮,然后启用它。

这是我有的:

    <div id="proceed">
    <a class="buttonlink" href="" ></a>
    <div class="button" id="button" style="opacity:0.4;filter:alpha(opacity=40);"></div
    </a>
    </div>

JS:

<script type="text/javascript">
    function showBuyLink() { 
    document.getElementById("button").style.opacity = "1.0";
    element.style.filter  = 'alpha(opacity=100)';
    var link = document.getElementsByClassName("button");
    links[0].onclick = function() {
        window.location.href = "proceed.html";
    }
    } 
    setTimeout("showBuyLink()", 5000); </script>

onclick不起作用,但不透明度确实有效。 有帮助吗?

如果要在加载页面后将按钮设置为启用,请使用java脚本函数document.onLoad()参考: http//www.w3schools.com/jsref/event_onload.asp

1)首先在HTML上将不透明度设置为0.4

2)在document.onLoad()上,因为它在整个页面加载后运行,将opacity设置为1并绑定click函数,然后参考: http//www.w3schools.com/jquery/event_bind.asp

尝试这个。

注意:不要忘记包含jquery.js

<script type="text/javascript">
$(document).ready(function(){
    $('#yourDivId').find('button').each(function () {
                    $(this).prop('disabled', true);
         });
    showBuyLink()
        $('#yourDivId').find('button').each(function () {
                    $(this).prop('disabled', false);
         });
    } 
    setTimeout("showBuyLink()", 5000); 
});
</script>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM