2012-02-23 57 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); 

});