问题描述
$(document).on("turbolinks:load",function() {
$('#client_phone').mask('(00)00000-0000');
});
它仅适用于第一个元素,当我单击“添加新字段”时,该掩码不适用。因此,我尝试使用茧形回调,例如:
$(document).on('turbolinks:load',function() {
$('#phone_clients').on('cocoon:after-insert',function() {
$('#client_phone').mask('(00)00000-0000');
});
});
但是它不起作用,我已经在回调中使用alert('something')进行了测试,并且它已经出现。所以我不知道为什么不使用口罩。
你们能帮我吗?
解决方法
请尝试以下操作:
$(document).on('turbolinks:load',function() {
$('#phone_clients').on('cocoon:after-insert',function(e,insertedItem) {
$(insertedItem).find('#client_phone').mask('(00)00000-0000');
});
});