0

I'm trying to achieve the seemingly impossible task of adding an mask to a input field.

I have the following code:

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();
}

Now I to get the .mask working on my input fields, so far I've only got it working on the new row I'm making and not on the original one.

Can anyone help me out?

4

1 回答 1

0

尝试替换您的代码:

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;
 });
于 2013-10-22T09:47:27.030 回答