jQuery mask is not working for loaded content

落花浮王杯 提交于 2019-12-11 08:23:40

问题


when the contents are loaded with ajax, the mask is not working on the input text.

What Should I do?

with thanks

Code:

$.ajax({url: path, data: {action:'create_form_profile'}, timeout:5000, type:"POST", success: function(data) {
    $("#_content").html(data);
    {
        $("#birth_date").mask("9999/99/99");
    }


    $("input:hidden").click(function(event) {
        window.location.href = "logout.php";
        sho‌​w_exit();
    });
}
});

回答1:


For me works this in ajax callback:

$('.phone').unmask().mask(phoneMask);

I don't understand why adding the same mask second time disables it..




回答2:


fire a change event on the input after changing its contents via ajax.

if the entire input comes from ajax then run the mask plugin on it and then fire the change event.

IE:

   $("#birth_date").mask("9999/99/99").change();



回答3:


I found the reason ;)

jquery.hotkeys-0.7.9.min.js was the cause.

I have the following js files included:

<script type="text/javascript" src="js/jquery-1.6.4.min.js"></script>
<!--<script type="text/javascript" src="js/jquery.hotkeys-0.7.9.min.js"></script>-->
<script type="text/javascript" src="js/_links.js"></script> 
<script type="text/javascript" src="js/_mask.js"></script>  
<script type="text/javascript" src="js/_lib.js"></script>
<script type="text/javascript" src="js/_general.js"></script>
<script type="text/javascript" src="js/_jq.js"></script>

and when I removed the second file, it was so



来源:https://stackoverflow.com/questions/10386852/jquery-mask-is-not-working-for-loaded-content

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!