有一个东西显示,另一个离开与jQuery

时间:2013-03-07 22:31:47

标签: javascript jquery html function show-hide

我在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(显示我的测试段落)。

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

2 个答案:

答案 0 :(得分: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')
        });
});

Codepen

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

答案 1 :(得分:0)

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

相关问题