开发者

replace it's not working

开发者 https://www.devze.com 2023-03-09 20:22 出处:网络
i don\'t know what\'s the cause but i just want to replace the caraceters with this values but i doesn\'t work could anybody see what i\'m doing wrong??

i don't know what's the cause but i just want to replace the caraceters with this values but i doesn't work could anybody see what i'm doing wrong??

$(document).ready(initialize);

function initialize() {
    $messageValues = $("#messagePreview");
    $("#txtMessageFields").keyup(previewData);

}

function previewData() {
    $messageValues.html('');
    var aux = this.value;
    aux.replace("#", '<span class="fieldText">');
    aux.replace('!', '</span>');
    $messageValues.append('开发者_如何学Go<p>' + aux + '</p>');
}

thanks for your time


replace is a function that returns a value; it doesn't modify the original string. Instead, assign aux to the value returned by replace:

 aux = aux.replace("#", '<span class="fieldText">');
    aux = aux.replace('!', '</span>');


.replace doesn't change the original string, it returns the modified string. You need to assign the returned value to something:

aux = aux.replace("#", '<span class="fieldText">');
aux = aux.replace('!', '</span>');
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号