2014-02-17 123 views
0

我的計劃是有一個部門有一個可以傳遞表單的onclick事件。請注意,該部門不是表格的一部分,相反,我想製作一個onclick函數來執行表單動作並將其放在目標上(順便說一句,這是一個iframe)。我的代碼是這樣的:如何使onclick函數提交表單並執行操作?

<style> 
    #myiframe { 
    position: absolute; 
    display:none; } 
</style> 
<script> 
    function myFunctionExecuteForm() 
    { 
     //(execute the action of the form here) 
    } 
</script> 
<iframe id="myframe" name="carsearch" scrolling="no" frameborder = "0" style = "position:absolute;top:42px; left:287px; width:723px; height:528px;"></iframe> 

<div onclick="myFunctionExecuteForm()">Save</div> //The division 

<form name="search" id="search" method="get" action="/crime_map/map_crime.php" target="carsearch"> 
</form> 

感謝您的幫助! :d

回答

1

做它用在點擊功能

document.forms["search"].submit();

0

使用jQuery像下面的代碼

jQuery('id/class of submitbutton').on('click',function(){ 
----your code here ------ 
} 

或使用這個網站

<form name="search" onsubmit="return function_name();" id="search" method="get" action="/crime_map/map_crime.php" target="carsearch"> 

0

我會給該div一個id或類,但下面應該工作

$("div").click(function() { 
    $("#search").submit(); 
}); 
相關問題