I am trying to achieve something very simple and I can't figure out where I'm going wrong.(我正在尝试实现一些非常简单的功能,但我无法弄清楚哪里出了问题。)
See the string below;(参见下面的字符串;)
My Name St Eugene’s Cathedral
I would like it to be;(我希望成为这样;)
my-name-st-eugene-s-cathedral
I need to remove all spaces and single quotes, replace with a hyphen and convert to lowercase.(我需要删除所有空格和单引号,并用连字符替换并转换为小写。)
My code so far is;(到目前为止,我的代码是;)
var str = "My Name St Eugene's Cathedral" str = str.replace(/'| /g,'-').toLowerCase(); alert(str)
Link to fiddle here http://jsfiddle.net/8z2jseyr/1/(链接到此处的小提琴http://jsfiddle.net/8z2jseyr/1/)
ask by jonboy translate from so