jquery - 检查所选元素是否包含空格

标签 jquery html

我正在尝试检查元素是否为空。

我的元素可能是这样的

<table>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td>text</td>
</table>

我试过:

$('table td').each(function(){
  if($(this).is(':empty')){
    console.log('found;)
  }
})

$('table td').each(function(){
  if($(this).html()=='&nbsp;'){
    console.log('found')
  }
})

但是我好像找不到。无论如何我可以做到这一点?非常感谢!

最佳答案

尝试像下面这样使用 $.trim

$.trim($(this).text()) === ''

关于jquery - 检查所选元素是否包含空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18092966/

相关文章:

javascript - string.indexOf ("*.") 在 Javascript 中做什么?

html - 是否可以有透明边框?

javascript - extjs 中的链接按钮

javascript - 如何设计带有子列表的列表,子列表应显示在父列表的悬停上

javascript - 设置不带显示的 tbody 高度 : block

jquery - 使用 jquery 或 javascript 删除图像后的 <br/>

jquery - 允许 HTML 内容超出父级的宽度

javascript - 鼠标离开的jquery问题

jquery - 选择 DOM 元素并添加值

javascript - 检查属性是否存在的简写函数