2011-02-28 82 views
2

嘿,我有一個條款和條件文本區域有一個滾動條和一個正常的ASP.NET按鈕下面。ASP.NET條款和條件,禁用按鈕直到向下滾動

我想知道如何禁用此按鈕,直到用戶滾動到條款和條件的結尾。

+2

請不要做這惹惱你的用戶! – DOK 2011-02-28 15:02:33

+0

我記得這樣的事情,在微軟合作伙伴網站.. – adt 2011-02-28 15:04:04

回答

2

這東西是最好的完成客戶端 - 你已經在使用一個庫如jQuery或其他什麼東西?

設置了以下工作一種享受:

<asp:TextBox runat="server" id="termsConditions" 
      TextMode="MultiLine" Rows="10" Columns="50"> 
    Lots of text here[...] 
</asp:textbox> 
<asp:button runat="server" id="accept" text="Accept" /> 

<script type="text/javascript"> 
    // Using jQuery, other options are available 

    // pick up the button, and disable it, keeping the button for later. 
    // Note the use of the ClientID property of the ASP.NET controls - this allows 
    // us to cleanly pick up the client side id of the objects. 
    var button = $("#<%= accept.ClientID %>"); 
    button.attr("disabled", "disabled"); 

    // pick up the textarea. 
    var terms = $("#<%= termsConditions.ClientID %>"); 

    // bind to the textarea's scroll event 
    terms.scroll(
    function() { 
    // Compare the scollHeight (the complete height of the textarea), with the 
    // combination of the current position (scrollTop) and the offsetHeight. 
    if (terms[0].scrollHeight < (terms[0].offsetHeight + terms[0].scrollTop)) { 
     // Re-enable the button 
     button.attr("disabled", null); 
    } 
    }); 
</script>