This question already has answers here:
Replace method doesn't work

(4个答案)


6年前关闭。



function areaMe(area) {
    var barea = $('#barea').val();
    if (barea.indexOf(area) != -1) {
        alert ("..." + barea + "..." + area + "...");
        barea.replace(area, "cu"); // Remove
        alert ("..." + barea + "..." + area + "...");
    }
    else {
        barea += area + ' '; // Include.
    }
    $('#barea').val(barea);
}

最佳答案

barea = barea.replace(area, "cu")

您需要分配它,因为String.prototype.replace不是mutator方法。

10-04 22:26