2011-11-19 31 views

回答

3

我不認爲這很重要。我會用這個代替

if (!fieldname.value.length) { 
    //it has no length (0) 
} 
2

在大多數情況下有用的解決方案是檢查比空間,如果用戶提供的文本不同,所以:

if (fieldname.value.match(/\S/g) !== null) { 
    // there is something more than spaces 
} 
+0

很好的回答。只是一個細節,簡單的不等式運算符'!='可以用在嚴格的不等式運算符'!=='中,因爲'match'方法永遠不會返回'undefined'。 – Luc125