【问题标题】:How would one select an element with the class="" using jQuery如何使用 jQuery 选择带有 class="" 的元素
【发布时间】:2016-09-09 20:34:48
【问题描述】:

我想使用 class="" 选择的文本如下所示:

<span class="">1&nbsp;Comment</span>

$('.').each(function(i,elem)... 似乎不起作用。

我还想解析文本,所以我得到整数值,而不仅仅是字符串文本“1”。

谢谢

【问题讨论】:

  • 你的班级名字是空的吗?
  • @Pete,没有类属性和类属性为空是有区别的。
  • 对于螺栓固定的,2-questions-for-the-price-of-1,第二部分,您可以乘以 1:var x = val * 1; 然后 x 是一个数字,如果 val 是 0不是数字。

标签: jquery class jquery-selectors


【解决方案1】:

您希望选择具有特定值的属性的元素。该值恰好是空字符串。

使用Attribute Equals Selector

$('[class=""]')

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-05
    • 2011-09-17
    • 2011-11-07
    • 1970-01-01
    • 1970-01-01
    • 2011-01-04
    相关资源
    最近更新 更多