2012-09-18 73 views

回答

2

劈在連字符字符串,大寫首字母,小寫休息...那就加入他們回來在空白處:

var string = 'this-is-a-test'; 
var words = string.split('-'); 
var list = []; 

for (var i=0, l=words.length; i<l; i++) { 
    var word = words[i]; 
    list.push(word.substr(0,1).toUpperCase() + word.substr(1, word.length).toLowerCase()); 
} 

console.log(list.join(" ")); 
+1

這很好,非常感謝你:) –