Вопрос

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