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

后端 未结 10 825
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:22

    if (!a) {
      // is emtpy
    }
    

    To ignore white space for strings:

    if (!a.trim()) {
        // is empty or whitespace
    }
    

    If you need legacy support (IE8-) for trim(), use $.trim or a polyfill.

提交回复
热议问题