简体   繁体   English

为什么这在IE10中不起作用,但在IE7中起作用

[英]Why would this not work in IE10, but works in IE7

I have a form that I want to break up into three different sections each with a "next" and "back" button to show the next or previous section respectively. 我有一个表格,我想分为三个不同的部分,每个部分都带有一个“下一个”和“后退”按钮,分别显示下一个或上一个部分。 For the most part it is working how i want, except in IE10+. 在大多数情况下,它的工作方式是我想要的,除了IE10 +。 it works in Firefox, Chrome, and IE7 (not sure about 8 and 9). 它适用于Firefox,Chrome和IE7(不确定8和9)。

the part of the code that isn't working is: 代码不起作用的部分是:

$("#sell_body2").hide();
$("#sell_body3").hide();


$('#sell_next1').click(function () {
    $("#sell_body1").fadeOut(250);
    setTimeout('$("#sell_body2").fadeIn(250)', 250);
});
$('#sell_next2').click(function () {
    $("#sell_body2").fadeOut(250);
    setTimeout('$("#sell_body3").fadeIn(250)', 250);
});
$('#sell_back2').click(function () {
    $("#sell_body2").fadeOut(250);
    setTimeout('$("#sell_body1").fadeIn(250)', 250);
});
$('#sell_back3').click(function () {
    $("#sell_body3").fadeOut(250);
    setTimeout('$("#sell_body2").fadeIn(250)', 250);
});

here is the jsfiddle http://jsfiddle.net/PHYL2/ in JSFiddle it works exactly how i want, but in IE10+ when i click the first "next" button, the current section fades out (like it should) but the next never fades in 这是JSFiddle中的jsfiddle http://jsfiddle.net/PHYL2/ ,它的工作原理完全符合我的要求,但是在IE10 +中,当我单击第一个“下一个”按钮时,当前部分淡出(像应该的那样),但是下一个永远不会淡入

NOTE: please excuse the horrid looks, i have only posted the code affected by the problem 注意:请原谅我看起来很恐怖,我只发布了受问题影响的代码

My guess is it's a problem deciphering / evaluating your timeout execution strings. 我的猜测是解密/评估您的超时执行字符串是一个问题。

Rather than setting a timeout, why not just use the fadeOut complete callback , eg 除了设置超时之外,为什么不直接使用fadeOut complete回调 ,例如

$('#sell_next1').on('click', function() {
    $('#sell_body1').fadeOut(250, function() {
        $('#sell_body2').fadeIn(250);
    });
});

I'd actually go a step further and make this much more generic. 我实际上将更进一步,使之更加通用。

Say your trigger elements look something like this... 假设您的触发元素看起来像这样...

<button id="sell_next1" class="next-btn"
    data-target-out="#sell_body1" data-target-in="#sell_body2">Hide body1, show body2</button>

Then you can write one generic handler... 然后,您可以编写一个通用处理程序...

$('.next-btn').on('click', function(e) {
    e.preventDefault();
    var $this = $(this),
        in = $this.data('target-in'),
        out = $this.data('target-out');
    $(out).fadeOut(250, function() {
        $(in).fadeIn(250);
    });            
});

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

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