文本方法在回调中不起作用

时间:2016-12-12 07:23:54

标签: javascript jquery

我提前为下面冗长的代码道歉,因为我无法确定问题的根源。我无法使用jQuery使用status.text()方法将文本插入.html() ID。我尝试在函数开头的回调之外使用.text(),它运行正常。但是,我希望能够只显示符合条件要求的文本。

我在这里添加了完整的工作代码:https://jsfiddle.net/p3wrov4u/

这是让我头疼的js的一部分。我注意到只有函数dogvideo会运行,程序似乎忽略了.text命令,甚至忽略了console.log m>=5。这可能是我犯的一些微不足道的错误,但我会感激一些帮助,因为我已经被困了几个小时了。

$('button#care').click(function(){ //last step
    //statusupdate = $('#status')
    //console.log('care for juno')
    c = localStorage.getItem("c")
    m = localStorage.getItem("m")
    e = localStorage.getItem("e")
    //an array of videos

    localStorage.setItem('bought',JSON.stringify(true))
    location.reload()

    if (m>=5){
        console.log('owowowowow');//run Juno mad video
        $('#status').text("watch out, juno's mad at the moment. don't get between him and his activities!");
        dogvideo(3)
    }
    else if (e>=10){
        console.log('run Juno excited video')
        $('#status').text("Juno's too excited to sleep, and he won't let you sleep either")
        dogvideo(1)
    }
    else if(c>=10){
        //run Juno content video
        numdays = localStorage.getItem("day")
        var content = JSON.parse(localStorage.getItem('content'))
        if (!content){
            localStorage.setItem('content', JSON.stringify(1))
        } else {
            localStorage.setItem('content',JSON.stringify(content + 1))
        }
        dogvideo(0)
        if (content == 6){
            $('#status').text('congrats. Juno is your dog!')
            //run celebration video
            //play again button?
        }
        else{
            console.log('working')
            $('#status').text('Keep Juno happy for ' + (7-content).toString() + ' more days for your big surprise!')
        }
    }
    else {
        $('#status').text("Juno is sad beacuse you didn't give him enough attention")
        dogvideo(2)
    }
bought = true
session+=1; 

0 个答案:

没有答案