2012-02-23 56 views
2

函数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

你可以做

$('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/

+0

工作很好,谢谢。我会在几分钟内接受这个答案。 – 2012-02-23 11:15:15

0

尝试增加letswinclick()

$(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); 

});