【问题标题】:AngularJs Select all attributed for an elementAngularJs选择一个元素的所有属性
【发布时间】:2016-09-01 11:42:15
【问题描述】:

有人可以建议我如何搜索与 AngularJS 中的查询匹配的选择器的属性。

我已尝试关注...

//1st Attempt
angular.element("editor-for[editor-title*='" + query + "']")
.each(function (index, value) {
}

//2nd Attempt
angular.element('editor-for:contains(' + query + ')')
.each(function (index, value) {
}

下面是打印到控制台的元素...

 <editor-for ng-model="merchant.header.logos.smallAbsoluteUrl" is-required="true" data-width="88" data-height="31" editor-title="Logo Url" editor-type="image" is-disabled="!isMasterSector" class="ng-pristine ng-untouched ng-valid ng-isolate-scope ng-not-empty" style=""></editor-for>

我的目标是搜索“editor-title”与查询匹配的任何元素。

我怀疑由于 Angular 使用 JQuery Lite,第二次尝试不起作用。谁能给点建议?

【问题讨论】:

    标签: jquery angularjs jquery-selectors


    【解决方案1】:

    我想您的代码由于查询中的错误 ' 字符而无法正常工作:CSS 无法将 ' 字符作为字符串分隔符处理。

    这样替换:

    angular.element("editor-for[editor-title*=\"" + query + "\"]")
    

    记住:在 CSS 中只能使用双引号 (") 作为字符串分隔符。

    【讨论】:

    • 我已更改为您的以下内容,但这仍然无法解决我的问题。
    • 你确定你也需要 * 令牌吗?
    • 我已经更新了我的问题以显示想要选择的元素 id 以及我尝试的第二种方法也不起作用。
    猜你喜欢
    • 1970-01-01
    • 2015-07-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多