简体   繁体   English

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

[英]Disable Div “Button” and then enable

I am trying to " disable " a div when the page loads, and then a few seconds later enable it. 我试图在页面加载时“ disablediv ,然后几秒钟enable它。 The effect I want to have is make the onclick return false for a few seconds, and have the opacity low. 我想要的效果是使onclick返回false几秒钟,并且不透明度低。 After the timer is up, I want the opacity to return to 1 and the onclick to be set to a function that sets the window.location.href to proceed.html. 计时器启动后,我希望不透明度返回到1并且onclick设置为将window.location.href设置为proceed.html的函数。 It's basically a button that is disabled for a few seconds, and then it is enabled. 它基本上是一个禁用几秒钟的按钮,然后启用它。

Here is what I have: 这是我有的:

    <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: 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>

The onclick doesn't work, but the opacity does. onclick不起作用,但不透明度确实有效。 Any help? 有帮助吗?

If you want to set button to enabled only after the page is loaded use the java script function document.onLoad() refer: http://www.w3schools.com/jsref/event_onload.asp 如果要在加载页面后将按钮设置为启用,请使用java脚本函数document.onLoad()参考: http//www.w3schools.com/jsref/event_onload.asp

1)First set the opacity to 0.4 on HTML 1)首先在HTML上将不透明度设置为0.4

2)On document.onLoad() since it runs after the whole page is loaded set opacity to 1 and also bind the click function then refer: http://www.w3schools.com/jquery/event_bind.asp 2)在document.onLoad()上,因为它在整个页面加载后运行,将opacity设置为1并绑定click函数,然后参考: http//www.w3schools.com/jquery/event_bind.asp

Try this. 尝试这个。

Note: Do not forget to include jquery.js 注意:不要忘记包含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