使用jquery-out-of-the-box测试空字符串的最佳方法是什么? [英] What is the best way to test for an empty string with jquery-out-of-the-box?
本文介绍了使用jquery-out-of-the-box测试空字符串的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用jquery-out-of-the-box测试空字符串的最佳方法是什么,即没有插件?我试过这个。
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 would be nice to use something that's builtin.
我不想重复
if (a == null || a=='')
无处不在如果某些 if(isempty(a))
可用。
everywhere if some if (isempty(a))
would be available.
推荐答案
if (!a) {
// is emtpy
}
忽略字符串的空格:
if (!a.trim()) {
// is empty or whitespace
}
如果您需要传统支持(IE8) - )对于 trim()
,请使用 $。trim
或 polyfill 。
If you need legacy support (IE8-) for trim()
, use $.trim
or a polyfill.
这篇关于使用jquery-out-of-the-box测试空字符串的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文