2014-04-29 37 views
-1

以下代碼在Chrome,Safari和Opera上完美工作,但在Mozilla Firefox上完美實現。無法將單擊事件從一個元素傳輸到另一個元素在Firefox中

$("#first").click(function() { 
    event.preventDefault(); 
    $("#second").click(); 
    return false; 
}); 
<form action="http://jsfiddle.net"> 
    <input type="submit" value="Go to Bing" id="first"> 
</form> 

<form action="http://example.com"> 
    <input type="submit" value="Go to adams" id="second"> 
</form> 

小提琴:http://jsfiddle.net/5GRVb/

【解析】:感謝@C-林

回答

1

你錯過了在函數中傳遞參數事件:

$("#first").click(function(event){ 
\\ ---------  here ^^ 
1

無需要將event.preventDefault()與返回false一起使用。這將工作。

$("#first").click(function(){ 
    $("#second").click(); 
    return false; 
}); 
相關問題