jquery replace < with " " (a space)
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(/[<>]/, ' ');
}
精彩评论