function isBlank(s){ // it is a function named 'isBlank' that accept one parameter, that the parameter is something passed from the outside
var len = s.length // Assign the length of parameter 's' into a local variable 'len'
var i // Declare a new local variable 'i'
for(i=0;i<len;++i) { // This is a 'loop', you can google it
if(s.charAt(i)!= " ") return false // if any character inside the parameter 's' is not an empty space, that means it isn't blank, so return false
}
return true; // If code reach this line that means 's' is either with 0 length or all characters of it are an empty space
}
通過使用上述函數:
alert(isBlank("123")); // false
alert(isBlank("")); // true
alert(isBlank(" ")); //true
@ OrangeFlash81你爲什麼拒絕我的編輯? –
@MehdiDehghani在我意識到您有待編輯之前,我做出了幾乎相同的更改。抱歉。 –
爲什麼你不能只讀這些方法,屬性等文件?這是非常基本的javascript,你可以在5分鐘內學到 –