Jquery.keypad.js不支持动态添加的文本框

jquery.keypad.js not working for dynamically added text box

本文关键字:文本 添加 动态 keypad js 不支持 Jquery      更新时间:2023-09-26

我使用jquery.keypad.js在用户可以选择的文本框中显示特殊字符(ÁÃÅÀ…)。对于文本框的第一个字段,当我通过单击"添加更多"按钮添加相同的文本字段时,它不起作用。我在点击"添加更多"后再次调用该函数,即使它不工作。有什么问题吗?

$(function () {
        $('.keypadactive').keypad({keypadClass: 'flatKeypad',keypadOnly: false, 
             layout: [<? echo  utf8_encode("'ÁÃÅÀÂÄááåàâäÆæßÇçÐÉËÈÊéëèê', 'ÌÎÍÏìîíïÑñÒÔÖØÓÕðòôöøóõÚÜÙ' ,'ÛùûúüÝýÿÿ¡,°¹²³º¼½¾±µ', '£¥'$¢þ§©®¯·¨¬«»¦ª¶'");?> ], prompt: '',showOn: 'button', buttonImageOnly: true, buttonImage: 'images/spl.jpg'});
});
$('.add_more').live('click',function(){
    $(this).parent().parent().parent().parent().append($('#add_me_next').html());
    $(this).parent().html('<label class="w50">&nbsp;</label><input type="button" name="remove" value="Remove" class="button remove" />');
    setTimeout('keypadCall()',1000);
});
function keypadCall(){
    $('.keypadactive').keypad({keypadClass: 'flatKeypad',keypadOnly: false, 
                 layout: [<? echo  utf8_encode("'ÁÃÅÀÂÄááåàâäÆæßÇçÐÉËÈÊéëèê', 'ÌÎÍÏìîíïÑñÒÔÖØÓÕðòôöøóõÚÜÙ' ,'ÛùûúüÝýÿÿ¡,°¹²³º¼½¾±µ', '£¥'$¢þ§©®¯·¨¬«»¦ª¶'");?> ], prompt: '',showOn: 'button', buttonImageOnly: true, buttonImage: 'images/spl.jpg'});
}

尝试将事件委托给最近的父节点,当dom准备好或$(document)本身具有.on()处理程序时可用:

$(document).on('click', '.add_more', function(){
    $(this).parent().parent().parent().parent().append($('#add_me_next').html());
    $(this).parent().html('<label class="w50">&nbsp;</label><input type="button" name="remove" value="Remove" class="button remove" />');
    setTimeout(keypadCall,1000);
});

,并尝试从setTimeout()keypadCall功能中删除()