简体   繁体   中英

Checking for IE7/IE6 in jQuery

I have a function where it needs to make allowances for the fact IE6/IE7 does not have the same support as other browsers, as follows:

if ($.browser.msie && $.browser.version.substr(0,1)<8) {
  $('table tr:nth-child(2n+1)').addClass('alternativeRow');
}

This has always worked fine, until I've just installed IE8 and I get a Javascript error message saying:

'$.browser' is null or not an object

I appreciate $.browser may not be the best way of checking these things anyway, so I was wondering if there was a way around it?

Thanks

(edit) to add a little context, I am simply trying to add a 'zebra' esque table layout since we deal with lots of data and it can be hard to analyse if each row looks the same

Quit Browser Sniffing and start feature sniffing.

http://modernizr.com/

.browser was deprecated in jQuery 1.3. The recommended solution is to use .support

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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