2014-11-04 32 views
0

叫我有以下的網頁,其中有複選框和文本框複選框沒有被jQuery的

`<asp:CheckBox ID="ChkCcList" runat="server" Text="Email CC list" />   
        </td> 
<td><asp:TextBox ID="txtEmail" TextMode="MultiLine" runat="server" MaxLength="200" Height="70px" Width="201px" Enabled = "false"></asp:TextBox> 
<asp:RegularExpressionValidator ID="RegularExpressionValidator" runat="server" ControlToValidate="txtEmail" 
ErrorMessage="<br />Please enter valid emails." ValidationExpression="\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*([;]\s*\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*)*"></asp:RegularExpressionValidator> 
<br /><br /></td> 
</tr>` 

jQuery代碼:

$('#ChkCcList').click(function() { 
    if (!$(this).is(':checked')) { 
     this.checked = confirm("Are you sure?");  
    } 
}); 

`

可以請你告訴我,爲什麼當點擊複選框時不會調用這個按鈕

+0

請提供呈現的HTML而不是您的服務器端代碼。 – PeterKA 2014-11-04 13:29:37

+0

這不是經典的asp,我已經將其重新命名爲asp.net – John 2014-11-04 16:28:47

回答

0

點擊事件處理程序需要註冊在$(document).ready I.e;

$(document).ready(function(){ 
    $('#ChkCcList').click(function() { if (!$(this).is(':checked')) { 
     this.checked = confirm("Are you sure?"); 
    } }); 
} 
2

你有一個asp.net控件,所以你不能只使用Id。您需要查看ChkCcList.ClientID以獲取屏幕上呈現的客戶端控件的ID。

相關問題