2010-02-28 13 views
3

jquery를 사용하여 확인란을 선택했을 때 2 개의 다른 마스크로 텍스트 상자를 마스크하려고합니다.jquery를 사용하여 ASP 텍스트 상자의 마스크

html 텍스트 상자 및 html 확인란을 사용하여 코드를 시도했지만 제대로 작동하지만 asp 텍스트 상자 및 asp 확인란을 사용하여 코드를 시도 할 때 응답이 없습니다.

어떤 조언 ???

여기 내 코드입니다 :

<%@ 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"> 

      $(document).ready(

function() { 

    $('#chkhtml').click(

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

}); 

$(document).ready(

function() { 

    $('#chkasp').click(

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

}); 
    </script> 


</asp:Content> 
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server"> 
    <asp:CheckBox ID="chkasp" runat="server" /> 
    asp:<asp:TextBox ID="txtasp" runat="server"></asp:TextBox> 
    <input id="chkhtml" type="checkbox" checked="checked" title="chkhtml" />HTML <input id="txthtml" type="text" />&nbsp; 

</asp:Content> 

답변

5

자신의 ID를,이 문제를 해결하기 위해 .ClientID을 사용 (귀하의 경우 아마도 더 이상 Content2$chkasp 대신 chkasp에서)보다 이상하는 INamingContainer 당신의 컨트롤이 다른 내부에있는 경우, 이 같은 :

$(function() { 
    $('#<%=chkasp.ClientID %>').click(function() { 
    if ($(this).is(':checked')) { 
     $("#<%=txtasp.ClientID %>").mask("999-99-9999"); 
    } else { 
     $("#<%=txtasp.ClientID %>").mask("99/99/9999"); 
    } 
}); 

또는 조건식 사용하여 아래로 단축 :

,651,658,321을 0
+0

감사합니다. 그게 도움이되었습니다. – SheldonH

관련 문제