2009-11-13 42 views

回答

3

當然有可能。我喜歡存儲臨時數據的方法是將它們存儲在對象/變量中。我只是不確定是否引用表格單元格或數據庫單元格,但基本上沒有區別。使用對焦它會是這樣的:

var $temp_before; 
var $temp_after; 
$('#cell_id').focus(function(){ 
    $temp_before = this.html(); // or this.text() depending on what you want to record 
    /*... call to function to change it ...*/ 
    $temp_after = this.html(); 
}); 

正如評論從Cory Larson建議,您還可以存儲自己使用jQuery data元素中的數據。

$('#cell_id').focus(function(){ 
    this.data("old_content", this.html()); 
    /*... call to function to change it ...*/ 
    this.data("new_content", this.html()); 
}); 
2

您可以使用jQuery將舊值寫入頁面上的隱藏字段,然後同時訪問編輯字段中的當前值和隱藏字段中的舊值。

+1

您甚至不需要隱藏字段 - 將舊值寫爲元素本身的屬性。 – 2009-11-13 20:28:24

+0

那就是我的想法。我試圖找出是否有其他方法可以做到這一點。 – Sridhar 2009-11-13 20:28:52

相關問題