简体   繁体   中英

jQuery <div> content swap script is not working with IE7 & IE8

The following thread provided me with a neat script to swap out div content and was authored by Carl Meyer .

Unfortunately the script does not work in IE7 & IE8 but works in Firefox 4+ and Chrome.

Does anyone know what i need to edit to get the script to work in IE7 & IE8?

Here is the script as i have edited it:

<script type="text/javascript" src="scripts/jquery-1.8.1.js"></script>
<script type="text/javascript">
    $(document).ready(function() {
    switches = $('#switches > div');
    slides = $('#slides > div');
    switches.each(function(idx) {
            $(this).data('slide', slides.eq(idx));
        }).hover(
        function() {
            switches.removeClass('active');
            slides.removeClass('active');             
            $(this).addClass('active');  
            $(this).data('slide').addClass('active');
        });
    });
</script>

<style type="text/css">
    #switches div.active {
      display: block;
    }   
    #slides div {
      display: none;
    }   
    #slides div.active {
      display: block;
    }   
</style>

<div id="switches" class="float_left">                      
 <div>switch 01</div>
 <div>switch 02</div>
 <div>switch 03</div>       
</div>

<div id="slides" class="float_left">
 <div class="active">(01) Slide content goes here</div>
 <div class="">(02) Slide content goes here</div>
 <div class="">(03) Slide content goes here</div>   
</div>

The switches and slides variables are not initialised and thus breaks in Internet Explorer, try adding 'var' infront

ie

var switches = $('#switches > div');

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