【问题标题】:Having one thing show, after another leaves with jQuery有一个东西显示,一个又一个离开 jQuery
【发布时间】:2013-03-07 22:31:47
【问题描述】:

我在这里在 JSFiddle 中制作了一个表格: http://jsfiddle.net/LCBradley3k/xqcJS/22/

我做了一个简短的段落,只是说“Hello World”,但在表单隐藏后它似乎没有运行(一旦所有用户输入正确的信息)。

这里是 Javascipt:

    if (correct) {

        $('#answer').html('Thank You!');
        setTimeout(function(){
    $('.inputs').hide("slide", { direction: "up" }, 1000);
    }, 2000);

        setTimein(function(){
    $('p').show("slide", { direction: "up" }, 1000);
    }, 2000);

 }

您可以看到 .inputs 隐藏了,但是在完成之后,我希望 setTimein 执行(显示我的测试段落)。

由于某种原因,它不起作用。有什么原因吗?

【问题讨论】:

  • 设置时间?这是新的。
  • 哦,哈哈。我没有意识到 setTimeout 实际上是内置在代码中的。对不起,我也是新人。
  • setTimeout是window的函数,可能是setTimein没有定义的错误?这将导致所有执行停止。

标签: javascript jquery html function show-hide


【解决方案1】:

HTML

<div id="answer"></div>
<input id="txt" placeholder="Say Something Smart" />
<input type="submit" />

JS

var $answer = $('#answer'),
    $txt = $('#txt'),
    $submit = $('[type=submit]')

$submit.click(function(){
    if(!$txt.val())
        return alert('enter something');
    $answer.html('Thank You!');
    $('input')
        .hide(200)
        .delay(2000)
        .show(200,function(){
            $answer.html('');
            $txt.val('').attr('placeholder','say something else')
        });
});

代码笔

http://codepen.io/anon/pen/uniGy

【讨论】:

    【解决方案2】:

    setTimein 不存在。那不是一回事。使用 setTimeout(function () {...}, 2000)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-10-21
      • 2011-12-09
      • 2017-08-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-09
      • 2022-01-19
      相关资源
      最近更新 更多