簡體   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