What is the best way to test for an empty string with jquery-out-of-the-box?

后端 未结 10 812
Happy的楠姐
Happy的楠姐 2020-11-29 15:45

What is the best way to test for an empty string with jquery-out-of-the-box, i.e. without plugins? I tried this.

But it did\'t work at least out-of-the-box. It woul

10条回答
  •  北海茫月
    2020-11-29 16:16

    The link you gave seems to be attempting something different to the test you are trying to avoid repeating.

    if (a == null || a=='')
    

    tests if the string is an empty string or null. The article you linked to tests if the string consists entirely of whitespace (or is empty).

    The test you described can be replaced by:

    if (!a)
    

    Because in javascript, an empty string, and null, both evaluate to false in a boolean context.

提交回复
热议问题