开发者

jquery replace < with " " (a space)

开发者 https://www.devze.com 2023-01-17 13:18 出处:网络
I\'m trying to replace the character开发者_C百科s < and > onblur with a space when someone enters it into my form.

I'm trying to replace the character开发者_C百科s < and > onblur with a space when someone enters it into my form.

I've got this at the moment

$(".tbAddress").blur(function() 
{ 
    $("<").replaceWith(" ");
    $(">").replaceWith(" ");
}

Any help would be much appreciated

thanks

Jamie


$(.tbAddress).blur(function(){
    $(this).val($(this).val().replace("<"," "));
    $(this).val($(this).val().replace(">",' "));
});

If your RegEx-Fu is better than mine, you can combine the two lines and pass in a Regular Expression as the first parameter to replace().


$(".tbAddress").blur(function() 
{
    this.value = this.value.replace(/[<>]/, ' '); 
}
0

精彩评论

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

关注公众号