开发者

How do I do a RegExp replace inside a jQuery template?

开发者 https://www.devze.com 2023-04-03 04:29 出处:网络
Suppose I have { price: \'$ 9.99 USD\' } and in my jQuery template I want to do this {{html String(price).replace(/([^A-Z ]+)/gi, \'<em>$1</em>\')}}

Suppose I have

{ price: '$ 9.99 USD' }

and in my jQuery template I want to do this

{{html String(price).replace(/([^A-Z ]+)/gi, '<em>$1</em>')}}

Check out this fiddle and notice the change in output that adding/removing the $1 makes: http://js开发者_如何学编程fiddle.net/brettwp/KNAtz/


Is $& what you want?

http://jsfiddle.net/KNAtz/5/

0

精彩评论

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