Jes*_*sen 7 css jquery cross-browser css-selectors jquery-selectors
在我的CSS中,我有一个必须应用于所有文本字段的规则(使用CSS3选择器input[type=text]
.
我也使用jQuery.某些浏览器(如Internet Explorer 6)不支持CSS选择器的表单.所以我的解决方法是在CSS中添加一个额外的类名:
input[type=text], .workaround_classname{
/* css styling goes here */
}
Run Code Online (Sandbox Code Playgroud)
然后通过jQuery添加CSS类:
$('input[type=text]').addClass('workaround_classname');
Run Code Online (Sandbox Code Playgroud)
问题是:如何在本机不支持CSS3选择器时确保仅调用此规则?
我最终在我的 javascript 文件中使用了条件注释。这样我就可以处理 IE6 并应用 CSS 类
$(function(){
//add css class to input[type=text] fields if the selector is not natively supported
// IE6 hack: Since some CSS selectors are not working, we simulate with class names.
/*@cc_on@if (@_jscript_version <= 5.6)
$('input[type=text],input[type=password],input[type=radio],input[type=checkbox]').
each(function() { $(this).addClass('type_' + this.type); });
@end@*/
});
Run Code Online (Sandbox Code Playgroud)
这样,我最终为所有表单字段添加了类名:
.type_text{}
.type_radio{}
.type_checkbox{}
.type_password{}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
15903 次 |
最近记录: |