原型选择器问题 IE 8

发布于 2024-10-01 04:53:42 字数 387 浏览 0 评论 0原文

我有一个使用以下 CSS 选择器的验证类(原型 1.6.1):

$$('*[class*=validate]')

这个想法是我为以“validate”开头的元素提供了各种类名称,即“validate-numeric”或“validate-url”。因此,我想获取 class 属性中带有 validate 一词的任何元素。

它几乎可以在任何其他浏览器中运行,包括 IE 6 和 IE 6。 7. 在 IE 8 中,它似乎没有选择正确的元素。我尝试在 IE 的开发人员工具中进行一些调试,但无论如何,控制台仅输出数组和对象的 {...} 。我有什么遗漏的吗?是的,它是一个 CSS3 选择器,但我认为它仍然在 Prototype 和 6 & 中实现。 7 人都使用过它。

I have a validation class that uses the following CSS selector (Prototype 1.6.1):

$('*[class*=validate]')

The idea is I have various class names for elements that start with 'validate', ie 'validate-numeric' or 'validate-url'. So, I'd like to grab any element with the word validate in the class attribute.

It works in just about any other browser, including IE 6 & 7. In IE 8, it doesn't seem to select the proper elements. I tried to do some debugging in IE's developer tools, but the console, in all it's wisdom, only outputs {...} for arrays and objects. Is there something I am missing? Yes, it's a CSS3 selector, but I thought it was still implemented in Prototype and 6 & 7 both worked with it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

墨洒年华 2024-10-08 04:53:43

如果您仍然没有弄清楚,这里有一个替代方案。对所有元素进行这样的分类:

<div class="validate numeric">foo</div>
<div class="validate url">bar</div>
<div class="validate email">world</div>

那么这肯定会在 IE8 中工作:

$('.validate');

我猜您正在编写一些用于表单验证的代码,这些是可能发生的错误。我的架构的 CSS 是,

.validate { color: red }
.numeric { margin: 1px }
.url { margin: 2px; }
.email { padding: 3px; }

而您的 CSS 架构不是模块化的 - 因此,随着您添加越来越多的错误类型,维护变得困难。

.validate_numeric,
.validate_url,
.validate_email {
 color: red;
}

.validate_numeric { margin: 1px }
.validate_url { margin: 2px; }
.validate_email { padding: 3px; }

If you still haven't figured out, here's an alternative. Classify all your elements as such:

<div class="validate numeric">foo</div>
<div class="validate url">bar</div>
<div class="validate email">world</div>

Then this surely will work in IE8:

$('.validate');

I'm guessing you're writing some code for form validation and these are errors that could occur. The CSS for my schema would be

.validate { color: red }
.numeric { margin: 1px }
.url { margin: 2px; }
.email { padding: 3px; }

Whereas your CSS schema wouldn't be modular - thus making it hard to maintain as your add more and more error types.

.validate_numeric,
.validate_url,
.validate_email {
 color: red;
}

.validate_numeric { margin: 1px }
.validate_url { margin: 2px; }
.validate_email { padding: 3px; }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文