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
Add a ment  | 

2 Answers 2

Reset to default 10

You'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