2013-04-06 56 views
1

我在嘗試使用JavaScript以編程方式調用按鈕的點擊。我的代碼是:調用按鈕的點擊處理程序

$(document).ready(function() { autoload(); }); 

function autoload() { 

    var button = $("#button"); 
    var video = $("#video"); 
    var evnt = button["onclick"]; 

    // Set the click handler of the button 
    button.click(function() { 
     video.get(0).play(); 
    }); 

    // Call the button's click handler 
    if (typeof button.onclick == "function") { 
     button.onclick.apply(button); 
    } 
} 

但出於某種原因,這是行不通的,單擊處理程序沒有被調用。

回答

4

Events在jQuery中是different而非本地DOM事件。

您應該使用button.click()button.trigger("click")