简体   繁体   English

IE8中的CSS3选择器?

[英]CSS3 Selectors in IE8?

Alright, so I recently found this script called " Selectivizr " and I was really excited, but I plugged it into my project, set it up just as it said, and it didn't work. 好吧,所以我最近发现这个名为“ Selectivizr ”的脚本,我真的很兴奋,但是我把它插入我的项目中,就像它说的那样设置它,但它没有用。

So, what I am looking for is any sort of JavaScript library/script that will allow me to use CSS3 selectors (especially :checked ) in IE8. 所以,我正在寻找的是任何类型的JavaScript库/脚本,它允许我在IE8中使用CSS3选择器(特别是:checked )。

Selectivizr seems broken, and hasn't been updated in over a year. Selectivizr似乎已经破裂,并且在一年多的时间里没有更新。 Has anybody else had luck with it? 还有其他人幸运吗?

Does anybody know of any other scripts that will allow for use of CSS3 selectors in IE8? 有没有人知道允许在IE8中使用CSS3选择器的任何其他脚本?

Not looking for CSS3 stylings like border radius, shadows, etc. Just looking for the selectors, like :before , :after , :checked , etc... 不寻找像边框半径,阴影等CSS3样式。只需寻找选择器,如:before:after:checked等...

Dean Edward's IE9.js is pretty solid, though I have heard of some incompatibility problems when using other libraries as well. Dean Edward的IE9.js非常可靠,但我在使用其他库时也听说过一些不兼容的问题。 Never experienced them myself, but haven't used the library too often in the wild for a long time. 从来没有经历过这些,但是很长时间没有在野外经常使用这个库。 Plug it and play, and if it doesn't break then you're all set. 插上它并播放,如果它没有破坏那么你就完全没了。

Link: http://code.google.com/p/ie7-js/ 链接: http//code.google.com/p/ie7-js/

Demos: http://ie7-js.googlecode.com/svn/test/index.html 演示: http//ie7-js.googlecode.com/svn/test/index.html

With jQuery code, you can use these few lines to toggle a class on all your checkboxes (or on it's container) any time it's checked or unchecked. 使用jQuery代码,只要选中或取消选中,您就可以使用这几行在所有复选框(或其容器)上切换类。 This then lets you use regular CSS code in all browsers. 然后,您可以在所有浏览器中使用常规CSS代码。

$("input[type='checkbox']").click(function() {
    $(this).parent().toggleClass("checked", this.checked);
});​

Working example here: http://jsfiddle.net/jfriend00/7jA5r/ . 这里的工作示例: http//jsfiddle.net/jfriend00/7jA5r/

If you dynamically create checkboxes, then you could use the dynamic form of .on() to make sure to catch them. 如果您动态创建复选框,那么您可以使用动态形式的.on()来确保捕获它们。

I would personally rather use a solution with a few lines of code like this than use a heavy library that tries to add CSS style file capabilities. 我个人宁愿使用像这样的几行代码的解决方案而不是使用一个试图添加CSS样式文件功能的重型库。 If you were going to use that, make sure you understand what's really going on under the covers before you adopt it. 如果您打算使用它,请确保在采用之前了解真正发生的事情。


If you just wanted a selector libraryby itself, the Sizzle selector library works across a wide variety of browsers including all the way back to IE6. 如果您只想要一个选择器库本身,Sizzle选择器库可以在各种浏览器中工作,包括一直到IE6。 It will adapt to the capabilities of the host browser, using as many built-in capabilities as are present and using it's own code when the host browser does not support an explicit capability. 它将适应主机浏览器的功能,使用与现有功能一样多的内置功能,并在主机浏览器不支持显式功能时使用它自己的代码。

You can use just the selector library itself from here or it is also the selector library inside of jQuery. 你可以从这里只使用选择器库本身,或者它也是jQuery中的选择器库。

It's extremely simple to use. 它使用起来非常简单。 You just do something like this: 你只需要这样做:

var items = Sizzle(":checked");

and you will have an array of DOM elements that match the selector. 你将拥有一个与选择器匹配的DOM元素数组。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM