문제

i have a simple modal box for a form page:

$('body').on('click', '#ayarlar', function (e) {
        $('#basic-modal-content').modal({ 
            overlayClose: true 
        });
        $('#basic-modal-content').load('http://www.myurl.com/inc/pages/islem/genel_ayarlar.php').modal();
        $('body').on('click', '#genel_ayarlar_guncelle', function (e) {
            var pass = $('#adminpass').val();
            var durum = $('#durum').val();
            $.ajax({
               type:"POST",
               url:"http://www.myurl.com/inc/pages/islem/genel_ayarlar_islem.php",
               data: {
                 pass: pass,
                 durum: durum
               },
                success:function(data){
                    $('#basic-modal-content').html(data).modal();
                }                   
            });
        });
        return false;
});

I want to trigger #genel_ayarlar_guncelle button's click when pressed enter key but my code doesn't work:

$('#adminpass').keypress(function(event){
  if(event.keyCode == 13){
     $('#genel_ayarlar_guncelle').click();
  }
}); 

I think it must have a simple solution but I am not expert in jquery or simplemodal box of Eric Martin.

도움이 되었습니까?

해결책

I'll guess that the input field is inserted with the load() call, as that seems like the only reason it wouldn't work, and then you'll need a delegated event handler

$('#basic-modal-content').on('keypress', '#adminpass', function(event){
    if(event.which === 13){
       $('#genel_ayarlar_guncelle').click();
    }
});
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top