jQuery过滤器选择器,对吗? [英] jQuery filter selector, is this right?
本文介绍了jQuery过滤器选择器,对吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这似乎行得通,但我不知道是否可以改善这一点.
It seems to work ok but I don't know if this can be impoved on or not.
我想选择所有具有edit-text-NUM或edit-html-NUM类的HTML标记,并更改其颜色.这就是我正在使用的...
I want to select any HTML tag that has a class of edit-text-NUM or edit-html-NUM and change the color of it. Here is what I am using...
jQuery(document).ready(function(){
jQuery('*')
.filter(function() {
return this.className.match(/edit-(text|html)-\d/);
})
.css({
'color': '#ff0000'
});
});
看起来还可以,正则表达式也可以吗?
Does that look ok and is the regex ok?
* edit:这样有效吗?我知道,如果jQuery('*')
是一个很大的页面,使用它可能会有点麻烦.它只需从<body>
向下工作,以便也许可以对其进行更改?
*edit: Also is this efficient? I am aware that using jQuery('*')
might be a bit of a hog if it's a large page. It only has to work from <body>
down so maybe it could be changed?
推荐答案
jQuery(document).ready(function(){
jQuery('body *')
.filter(function() {
return this.className.match(/edit-(text|html)-\d/);
})
.css({
'color': '#ff0000'
});
});
应将其限制为文档正文
这篇关于jQuery过滤器选择器,对吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文