jQuery mask is not working for loaded content

2019-08-05 04:51发布

问题:

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



标签: jquery ajax mask