未定义的函数错误

时间:2012-02-23 11:08:39

标签: javascript jquery

功能letswin()无效。我无法找到解决方法。

var pathArray = window.location.pathname.split( '.html' );
var pathArray = pathArray.reverse();
var pathArray = pathArray .join('');
var pathArray= pathArray .split('/');
var bidnum=pathArray[3];
$(document).ready(function(){           
    $('body').append("<div id=\"cdjs\" style=\"position: absolute; top: 30px; background-color: gray; box-shadow: 0px 0px 0px 3px; left: 30px;\" onClick=\"letswin()\">Click to start</div>");
});

function checkandbid(){
    $.get("http://www.bigibid.com/LiveResponder/LR.bid?_as="+bidnum, function(data){
        Marray = data.split("'te':'")
        time = Marray[1].split("'")
        time = time[0]
        $('#cdjs').html(time);
        if (time < 2 && able==1){
            able=0;
            $('#ctl00_ContentPlaceHolder1_ibBid').click();
        } else {
            able=1;
        }
    });
}

function letswin(){
    setInterval(checkandbid, 300);
}

您可以使用jsFiddle

2 个答案:

答案 0 :(得分:2)

你可以做到

    $('body').append("<div id=\"cdjs\" style=\"position: absolute; top: 30px; background-color: gray; box-shadow: 0px 0px 0px 3px; left: 30px;\" >Click to start</div>");
    $('#cdjs').click(letswin); 

在这里摆弄http://jsfiddle.net/LKZcT/6/

答案 1 :(得分:0)

尝试在click()中添加letswin

$(document).ready(function(){

    $('body').append("<div id=\"cdjs\" style=\"position: absolute; top: 30px; background-color: gray; box-shadow: 0px 0px 0px 3px; left: 30px;\" >Click to start</div>").click(letswin);

});