2012-06-26 31 views
0

我用JEditable製作編輯的字段,它下面的代碼:如何發送舊版本的領域

 $(function() { 
       $(".field").editable("http://localhost/index.php/welcome/update_record", { 
       event : "mouseover", 
       style : "inherit", 
       submit : "save", 
       callback: function(value, settings) { 
        //some code 
        } 
       }); 
    }); 

我需要更新數據庫中的字段的值,但如果用戶沒有進入系統與他的登錄/密碼對,我需要顯示關於它的消息並返回該字段的舊值。那麼,我怎樣才能發送字符串的舊值呢?我如何將它添加到$ _POST數組?謝謝。

回答

0

在這裏你去 - 會做一個以上的在同一時間:

$(function() { 
    $(".field").each(function() { 
      var old_value = $(this).text(); //save old value 
      $(this).editable("http://localhost/index.php/welcome/update_record", { 
      event : "mouseover", 
      style : "inherit", 
      submit : "save", 
      callback: function(value, settings) { 
        $(this).text(old_value); 
       } 
      }); 
    }); 

}); 
0

你能澄清你的舊字符串是什麼意思嗎?如果你的意思是字段的值,你來了編輯之前,請保存值的變量:

$(function() { 
      var old_value = $(".field").text(); //save old value 

      $(".field").editable("http://localhost/index.php/welcome/update_record", { 
      event : "mouseover", 
      style : "inherit", 
      submit : "save", 
      callback: function(value, settings) { 
       //do something with old_value here 
       } 
      }); 
}); 

編輯:如果它是一個文本框,而不是一個容器 - 使用$(「字段」)VAL(。 );而不是文字。

+0

非常感謝您 – user1477886

+0

另外,請告訴我,我怎麼可以將該值設置爲回調函數領域? – user1477886

+0

我對這個插件並不熟悉,但是我想''(this).text(old_value);'在回調函數中會做到這一點。 – Chris