3

我在我的應用程序中使用struts2-jquery插件,我使用它的sj:一個組件來提交表單。Struts2 jquery構象

這是我的代碼。

<s:iterator value="countryList" var="country"> 
    <s:form id="frm%{countryID}" action="add_country_save"> 
     <s:textfield name="country.countryName" size="40" id="txt%{countryID}"/> 
</s:form> 

<sj:a id="ah%{countryID}" formIds="frm%{countryID}" 
targets="add_country" button="true" > Delete </sj:a> 

</s:iterator> 

一切正常,直到需求提出,我必須在提交表單之前顯示確認對話框。

這實際上是我試圖實現的。

如果用戶點擊確定,表單提交將被提交。 如果用戶點擊取消,表單提交將被取消。

如果有人有解決方案,請與我分享。

感謝的

回答

3

你指定的ID由服務器端生成的,所以你不能很容易地選擇自己的ID,因爲它會從你的數據庫不同的結果會有所不同。

達到目標的最簡單方法就是這樣。

<form onsubmit="return confirm('Do You Want to Submit the Form?');"> 

如果您有多個表單,我會建議在您的表單中添加一個名稱屬性。

<s:form id="frm%{countryID}" name ="myform" action="add_country_save"> 
    <s:textfield name="country.countryName" size="40" id="txt%{countryID}"/> 

並將一個事件處理程序附加到具有該名稱屬性的所有窗體。

$('form[name ="myform"]').click(function(){ 
    if(confirm('Do you want to submit the form?')){ 
     $(this).submit(); 
    } 
}); 
+0

謝謝你..沒關係 – edaklij 2013-02-23 09:41:33