2009-09-19 6 views
0

일부 입력 (텍스트 유형)이 있습니다. 나는 하나를 제외하고 모두를위한 동일한 행동을 원합니다. jQuery : 바인딩 keydown, 하나만 제외하고 같은 동작

당신이 나를 도울 수 ....

$(document).ready(function() { 

    $("input[type=text]").bind('keydown', function(e) { 
     .... 
    }); 

    $("#MyOtherInput").keydown(function(e) { 
     ..... 
    }); 

}); 

MyOtherInput 특정 동작과 입력 타입 texte입니다 :

나는이 시도?

감사합니다.

답변

1

이 시도 :

$('input[type=text]').not('input[type=text]#MyOtherInput').bind('keydown', function(e) 
{ 
    ............ 
}); 

그것은 예를 아래에 myotherinput control.Try 제외하고 텍스트를 입력 모든 입력을 선택합니다.

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server"> 
    <title></title> 

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script> 

</head> 
<body> 
    <div id="testdiv"> 
     <input id="Text1" type="text" /><br /> 
     <input id="Text2" type="text" /><br /> 
     <input id="Text3" type="text" /><br /> 
     <input id="Text4" type="text" /><br /> 
     <input id="Text5" type="text" /><br /> 
     <input id="Text6" type="text" /><br /> 
     <input id="MyOtherInput" type="text" /> 
    </div> 
</body> 

<script type="text/javascript"> 

    $(function() 
    { 
     $('input[type=text]').not('input[type=text]#MyOtherInput').bind('keydown', function(e) 
     { 
      alert('Common for all '); 
     }); 

     $('input[type=text]#MyOtherInput').bind('keydown', function(e) 
     { 
      alert('Only for MyOtherInput'); 
     });   

    }); 

</script> 

</html> 
+0

및 2 개의 예외가 있습니까? –

+0

그 클래스의 이름이 testclass라는 가정하에 두 개의 컨트롤에 별도의 클래스를 할당하십시오. 코드는 다음과 같을 것입니다 : $ ('input [type = text]'). not ('input [type = text] .testclass') ......... – Raghav

0

특정 이벤트가 필요한 필드에서 이벤트를 바인딩 해제하면됩니다.

$("#MyOtherInput").unbind("keydown").keydown(function(){}); 
0

당신은 입력 상자를 얻을 수있는 클래스 이름을 사용하고이

$(document).ready(function() { 

    $(".InutClass").bind('keydown', function(e) { 
     .... 
    }); 

}); 

위의 코드는 InputClass, 입력 필드에 대한 CSS 클래스가 모든 요소를 ​​결합 할 수 있습니다.

관련 문제