function toCamelCase(s) {
// remove all characters that should not be in a variable name
// as well underscores an numbers from the beginning of the string
s = s.replace(/([^a-zA-Z0-9_\- ])|^[_0-9]+/g, "").trim().toLowerCase();
// uppercase letters preceeded by a hyphen or a space
s = s.replace(/([ -]+)([a-zA-Z0-9])/g, function(a,b,c) {
return c.toUpperCase();
});
// uppercase letters following numbers
s = s.replace(/([0-9]+)([a-zA-Z])/g, function(a,b,c) {
return b + c.toUpperCase();
});
return s;
}
Prova questa funzione, spero che aiuta.
fonte
2015-05-29 05:07:00
Prova questo link compagno che ti aiuta di sicuro http://jamesroberts.name/blog/2010/02/22/string- funzioni-per-javascript-trim-to-camel-case-to-dashed-e-to-underscore/ – Santhucool