简体   繁体   中英

make particular word (string) in caps with jquery

I have a word "Real" in the website I don't want to search it page by page and make it caps.

I am trying to make "Real" word in caps through jquery and I am using the below code:

$('jqueryselector').val($(this).val().toUpperCase());
<html> code Real Change Fellowship

The above code is making whole text in caps and i just want to make "Real" word in caps.

Please help.

In case your code above is working ( .val() , really?), in order to uppercase just "real" and not the whole string, you'd need to do a string replace:

$(this).val().replace(/real/gi, 'REAL');

As pointed out by Jaromanda in comments, the actual expression could be improved upon, pending your exact requirements, but this would be the general idea.

There are conceptual issues with this, however, if you're doing this because "Real" is an abbreviation. You will never be able to definitely distinguish the abbreviation from all uses of the English word "real". If at all an option, I would definitely consider getting the source content right rather than trying to patch it up post hoc. Most IDE's should come with a "search and replace in all files" functionality.

以下将把“真实”一词更改为“真实”

 $('jqueryselector').val($(this).val().replace(\bReal\b/gm, 'REAL'));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM