admin管理员组文章数量:1279219
I am using the following code to convert a dynamic string into a valid class.
domain.replace('.','_','gi')
This works fine in all major browsers, but not in Internet Explorer and I'm wondering why. The gi flags are for global and case insensitive, but removing them means that the replace doesn't work in Firefox either.
Any ideas on how I change this to make it more friendly with more browers?
I am using the following code to convert a dynamic string into a valid class.
domain.replace('.','_','gi')
This works fine in all major browsers, but not in Internet Explorer and I'm wondering why. The gi flags are for global and case insensitive, but removing them means that the replace doesn't work in Firefox either.
Any ideas on how I change this to make it more friendly with more browers?
Share Improve this question asked Dec 6, 2010 at 17:58 David YellDavid Yell 11.9k13 gold badges64 silver badges102 bronze badges 1- 1 What happens or doesn't happen? What is the expected and actual result? – Pekka Commented Dec 6, 2010 at 17:59
2 Answers
Reset to default 10You'll need to use an actual regexp instead of a string:
domain.replace(/\./g, "_")
The third argument (flags) is non-standard.
You need to do it like this:
domain.replace(/\./g, '_');
本文标签: Cross browser Javascript regexStack Overflow
版权声明:本文标题:Cross browser Javascript regex - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741260721a2367568.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论