Jquery 将掩码添加到输入

Jquery 将掩码添加到输入,jquery,mask,Jquery,Mask,我试图完成一项看似不可能的任务,即在输入字段中添加一个掩码 我有以下代码: function addActivationCode(){ newRow = jQuery("div.activationcode:last-child").clone(); newRow.insertAfter(jQuery("div.activationcode:last-child")); newRow.attr("id", "coderow-" + Math.round(Math.random() * 10000

我试图完成一项看似不可能的任务,即在输入字段中添加一个掩码

我有以下代码:

function addActivationCode(){
newRow = jQuery("div.activationcode:last-child").clone();
newRow.insertAfter(jQuery("div.activationcode:last-child"));
newRow.attr("id", "coderow-" + Math.round(Math.random() * 10000));
newRow.find("input").val("");
find("input").mask("9999-9999-9999-9999");
newRow.find("a.coderemove").attr("onclick", "removeActivationCode('" + newRow.attr("id") + "'); return false;");
}

function removeActivationCode(id){
jQuery("div#" + id).remove();
}
现在我要让.mask在我的输入字段上工作,到目前为止,我只让它在我正在制作的新行上工作,而不是在原来的一行上


有人能帮我吗?

尝试替换您的代码:

newRow.find("a.coderemove").attr("onclick", "removeActivationCode('" + newRow.attr("id") + "'); return false;");
为此:

var rowId = "coderow-" + Math.round(Math.random() * 10000);
newRow.attr("id", rowId); // newRow.prop("id", rowId);
newRow.find("a.coderemove").on("click", function(e){
    e.preventDefault();
    removeActivationCode(rowId);
    //return false;
 });