2010-02-28 35 views
0

我有asp.net頁面中的文本框和複選框。 如果選中的複選框應該有一個輸入掩碼,並且它的取消選中應該有另一個輸入掩碼。我的代碼總是選擇第二個條件,我被告知應該添加click事件來運行代碼,無論何時點擊複選框,並且因爲我是新的jquery,我需要幫助將點擊事件添加到我的腳本。jquery與複選框在asp.net中添加點擊事件

請大家幫忙。

這裏是我的代碼:

<%@ Page Title="" Language="C#" MasterPageFile="~/Imam.Master" AutoEventWireup="true" 
    CodeBehind="WebForm4.aspx.cs" Inherits="Imam_Contacts.WebForm4" %> 
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server"> 

<script src="js/jquery-1.4.1.js" type="text/javascript"></script> 


<script src="js/jquery.maskedinput-1.2.2.js" type="text/javascript"></script> 
    <script type="text/javascript"> 



    $(function() { 
if ($('#chkhtml:checked').length > 0) { 
    $("#txthtml").mask("999-99-9999"); 
    } else { 
    $("#txthtml").mask("99/99/9999"); 
    } 
}); 

</script> 


</asp:Content> 
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server"> 

<input id="chkhtml" type="checkbox" checked="checked" /> 

</asp:Content> 

回答

0

此代碼對我的作品。

$(document).ready(

function() { 

$('#chkhtml').click(

    function() { 
    if ($('#chkhtml:checked').length > 0) { 
    $("#txthtml").mask("999-99-9999"); 
} else { 
    $("#txthtml").mask("99/99/9999"); 
} 
}); 

}); 
1

你要做

<script src="js/jquery.maskedinput-1.2.2.js" type="text/javascript"></script> 
    <script type="text/javascript"> 

    $(function() { 
    if ($('#chkhtml:checked')) { 
     $("#txthtml").mask("999-99-9999"); 
    } else { 
     $("#txthtml").mask("99/99/9999"); 
    } 
    }); 

</script> 
+0

當我用你的代碼只調用的代碼的第一部分,當我選中此複選框沒有發生。 我想我需要添加點擊甚至! 你可以跟我說說或告訴我我該怎麼辦? – Eyla 2010-02-28 11:01:16

相關問題