ExtJs 6.0-Ext.dom.Element.query()-属性中的多个值-正确的选择器
ExtJs 6.0 - Ext.dom.Element.query() - multiple values in attribute - correct selector
我的Sencha小提琴看起来像这样:
Ext.application({
name : 'Fiddle',
launch : function() {
var my_panel = Ext.create('Ext.panel.Panel', {
html: "<img id='1' foo='4 6 8' src='http://i342.photobucket.com/albums/o416/TaySensei/avatar_me_in_anime_1_by_maria345.jpg'/>" +
"<img id='2' foo='5 7 9 10' src='http://i621.photobucket.com/albums/tt296/Kruh11/KruhPic50x50LQ.jpg'/>" +
"<img id='3' foo='6 4' src='http://i744.photobucket.com/albums/xx84/no_photos_here/communitytile-1.jpg'/>"
});
var my_viewport = Ext.create("Ext.container.Viewport",{
layout: 'fit',
items: [my_panel],
renderTo : Ext.getBody()
});
var queried_imgs = my_panel.body.query("img[foo='4']");
Ext.toast('queried_imgs = ' + queried_imgs);
}
});
我的问题是:
在第15行中,我尝试使用Ext.dom.Element.query(selector)
-方法查询img
标记,该标记的foo
属性中包含值4
。
然而queried_imgs
是空的。
检索foo
属性中包含4
的img
标记的正确CSS选择器是什么
以下是各种属性选择器,它们根据元素的属性和值来选择元素。你可以用最适合你情况的。您可以在W3C selectors Spec.中找到有关各种可用CSS属性选择器的更多详细信息
img
标签的CSS选择器,该标签具有值包含4-img[foo*='4']
的foo
属性
img[foo*='4']{
border: 5px solid red;
}
<img src='http://lorempixel.com/100/100/nature/4' foo='4 5' /> <!-- will select this -->
<img src='http://lorempixel.com/100/100/nature/4' foo='41' /> <!-- and this -->
<img src='http://lorempixel.com/100/100/nature/4' foo='14' /> <!-- and this -->
<img src='http://lorempixel.com/100/100/nature/4' foo='4' /> <!-- and this -->
注意:我相信您只是在寻找上面的选择器。
img
标记的CSS选择器,该标记具有值以4-开头的foo
属性img[foo^='4']
img[foo^='4']{
border: 5px solid red;
}
<img src='http://lorempixel.com/100/100/nature/4' foo='4 5' /> <!-- will select only this -->
<img src='http://lorempixel.com/100/100/nature/4' foo='41' /> <!-- and this -->
<img src='http://lorempixel.com/100/100/nature/4' foo='14' />
<img src='http://lorempixel.com/100/100/nature/4' foo='4' /> <!-- and this -->
img
标签的CSS选择器,该标签具有值正好为4-img[foo='4']
的foo
属性
img[foo='4']{
border: 5px solid red;
}
<img src='http://lorempixel.com/100/100/nature/4' foo='4 5' />
<img src='http://lorempixel.com/100/100/nature/4' foo='41' />
<img src='http://lorempixel.com/100/100/nature/4' foo='14' />
<img src='http://lorempixel.com/100/100/nature/4' foo='4' /> <!-- will select only this -->
img
标签的CSS选择器,该标签具有foo
属性,该属性具有空格分隔值列表,其中一个值恰好为4-img[foo~='4']
img[foo~='4']{
border: 5px solid red;
}
<img src='http://lorempixel.com/100/100/nature/4' foo='4 5' /> <!-- this will select this -->
<img src='http://lorempixel.com/100/100/nature/4' foo='41 21' />
<img src='http://lorempixel.com/100/100/nature/4' foo='14 34' />
<img src='http://lorempixel.com/100/100/nature/4' foo='4' /> <!-- and this -->
<img src='http://lorempixel.com/100/100/nature/4' foo='159 4' /> <!-- and this -->
注意:~=
选择器将选择代码中的元素#1
和#3
。但它并不是完全选择foo属性包含4的元素。
相关文章:
- jQuery最近父级的数据属性选择器
- JavaScript选择器:查找包含具有特定属性的子体的节点
- 使用javascript和css选择器获取value属性的内容
- 自定义jquery选择器属性未在模拟器中激发
- 如何为HTML属性/选择器创建全局名称空间或变量
- 如何更改剑道时间选择器的禁用属性
- 属性选择器不起作用(语法错误、无法识别的表达式)
- 在 Jquery 中更改变量选择器的属性
- 获取具有选择器值的属性
- 基于html属性的动态jquery选择器
- MVC4和日期选择器:“;0x800a01b6-JavaScript运行时错误:对象没有't支持属性或方法
- 动态添加数据时按数据属性查询JQuery选择器
- DOM元素的属性因选择器-jQuery而异
- 为什么属性选择器不适用于jQuery
- 在 jQuery 选择器中使用 HTML5 数据属性
- 未定义访问具有对象属性的jquery选择器
- 如何使用用户界面选择组筛选器属性
- 如何在访问选择器后访问 css 选择器属性
- 为什么jQuery:not选择器属性没有'不适用于这种情况
- jQuery选择器属性范围