【问题标题】:Jquery : Attribute Start With for current elementJquery:当前元素的属性开头
【发布时间】:2013-11-18 16:12:02
【问题描述】:

jquery 中的“Start With”属性很简单,但是我有一个问题 如何将此属性用于当前元素? 例如我试过:

$('this[id^= "PostTypes"]') 

$(this[id^= "PostTypes"])

但没有什么想要的。

【问题讨论】:

  • 你想做什么
  • @ArunPJohny 我尝试获取当前元素的 id,如果它带有“PostTypes”的统计信息,请进行一些更改

标签: jquery jquery-attributes


【解决方案1】:

试试,

 $('[id^= "PostTypes"]', this); // if you want to find the elements that are descendants of this.

或者如果你想检查当前元素是否匹配,那么你可以使用.is(selector):

$(this).is('[id^= "PostTypes"]'); //Check if this element is havind the id startswith PostTypes.

例子:

if($(this).is('[id^= "PostTypes"]')){
   //Current element starts with id PostTypes, do something with it.
}

【讨论】:

    【解决方案2】:

    使用filter()

    $(this).filter('[id^= "PostTypes"]')
    

    【讨论】:

      【解决方案3】:

      我相信你想要:

      $('[id^="PostTypes"]', this)
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-07-26
        • 1970-01-01
        • 2017-07-20
        • 2013-09-28
        • 2017-05-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多