2011-05-12 25 views

回答

1

我想JavaScript可以處理這個。爲此,技術上有不同的方法。其中之一是有一個功能,將驗證字段/頁面是否有任何更改。該功能將首先由其他選項卡功能調用。

在加載頁面時,將字段的所有值存儲在一個變量或隱藏字段中作爲連接。但是你可以通過變量分開它,然後再連接它。

ex. var gOldValue = 'value1value2value3....'; //The value1.... is generated via JSP 

創建一個將gOldValue值與包含在該gOldValue這是基礎,如果有在網頁的變化各領域的當前值的函數。

function isPageChanged(form){ 
    var currentValue = ""; 
    for(var i = 0; i < form.length; i++){ 
     //Assuming all elements in the form have the value that stored in `gOldValue` 
     //upon loading. Now check its current value if will be same. 
     currentValue += form.elements(i).value; 
    } 

    //Return a value that will indicate that pages have been changed 
    if(gOldValue != currentValue){ 
     return true;    
    }   
    return false; 

} 

其他選項卡在執行主函數之前可能會先調用isPageChanged()函數。

<input type="button" onClick="showNextPage()" value="Next" />.... 

function showNextPage(){ 
    if(isPageChanged()){ 
     var isConfirm = confirm("Do you want to save changes"); 
     if(isConfirm){ 
      //Save the changes 
     } 
    } 
    //Else do some stuff... 

} 
+0

非常感謝您的善意幫助:) :) :) – 2011-05-12 14:06:05