2012-12-07 3 views
0

나는 jsp에서 아래의 함수를 사용하여 대화 상자를 만들고 엽니 다. 이 dalog에는 텍스트 상자가 있습니다. 내가 Jquery 대화 상자에서 버튼 클릭 이벤트 생성하기 Enter?

function createCustomerDialog(){ 
    $("#createCustomerDialog").dialog({ 
     title : ""Create Customer, 
      buttons : { 
      'CreateCustomer' : function() { 

     }, 
      'Cancel': function() { 
       $(this).dialog("close"); 
      } 
     } 
     }); 
     $("#createCustomerDialog").dialog("open"); 

} 

내가이 시도하지만, 키 코드 == 13 대화 입력의 때 onKeyPress 이벤트 체크에

$('.ui-dialog-buttonpane > button:last').focus(); 

답변

1

작업 dnot 핥았해야이 대화 CreateCustomer 버튼을 입력 할 때 내가 원하는 것은 (ENTER 키)이 코드에 도달하면 버튼을 클릭하십시오. 있다는 이유 CreateCustomer 버튼을 먼저 것, 제 1 선택 :

$('.ui-dialog-buttonpane > button:last').focus(); 

그리고 당신이 버튼을 시도해야한다고 생각 :

$("#yourInputId").keypress(function (e) { 
    if (e.keyCode == 13) 
     $("#yourButtonId").click(); 
}); 
0

대신이 코드에서 .focus() 메소드()는 .click 사용해야 할 수 있습니다.

$("#dialog-confirm").dialog({ 
      resizable: false, 
      height:140, 
      modal: true, 
      buttons: { 
       "Delete all items": function() { 
        $(this).dialog("close"); 
      alert('Delete all items clicked'); 
       }, 
       Cancel: function() { 
        $(this).dialog("close"); 
      alert('Cancel clicked'); 
       } 
      } 
     }); 

그리고 브라우저 콘솔에서이 시도 :

$('.ui-dialog-buttonpane button:first').click(); 
관련 문제