2016-03-30 6 views

Antwort

3

Dies funktioniert 100%.

function Sum(){ 
var myString = "Hello World"; 
var withoutSpace = myString.replace(/ /g,""); 
var length = withoutSpace.length; 
alert(length); 
} 
2
**For length including white-space:** 

$("#id").val().length 

**For length without white-space:** 

$("#id").val().replace(/ /g,'').length 
**For removing only beginning and trailing white-space:** 

$.trim($("#test").val()).length 
**For example, the string " t e s t " would evaluate as:** 

*//" t e s t "* 
$("#id").val(); 

**//Example 1** 
$("#id").val().length; //Returns 9 
**//Example 2** 
$("#id").val().replace(/ /g,'').length; //Returns 4 
**//Example 3** 
$.trim($("#test").val()).length; //Returns 7 

Versuchen Sie hoffen, dass es für Sie arbeitet