开发者

If condition checking for two TextFields Value

if(a.value === undefined || a.value.length>37 || 
        b.value === undefined |开发者_运维技巧| b.value.length > 256) {

If the first one is undefined or greater than a length of 37. I get a error, but it does not check for the second field at all.


use parenthesis. It checks from left to right and stops once it hits a fail the way you have it set up. Try

if((a.value === undefined || a.value.length>37) || 
(b.value === undefined || b.value.length > 256)) {


Conditional evaluation is lazy, i.e. it stops as soon as the result has been determined. That is, if (A && B) will not evaluate B if A is false, because the conjunction will have to be false already, and similarly if (A || B) will not evaluate B if A is true because the disjunction is already true.


You're forgetting what an OR in logic means. It only going to check until it finds one true statement.

Try regrouping:

((a.value === undefined || a.value.length>37)
                   ||
 (b.value === undefined || b.value.length > 256))

Just about elevating the condition a bit, and bringing a more broad result back instead of chasing the first true response.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜