jQuery: 只有改变值才能提交 jeditable only submit if changed

原代码:

    $(document).on("mouseover","td.editable",editable_input);
  	
  	function editable_input()
  	{
  		var $editable_type = $(this).attr('editable_type');
  		if($editable_type == 'text' || $editable_type == 'textarea')
  		{
			$(this).editable(BASEPATH + "/editable", { 
			    indicator  : '<img src="'+BASEURL+'public/assets/indicator.gif" />',
			    type       : $editable_type,
			    submit     : "OK",
			    cancel     : "Cancel",
			    onblur     : "cancel", //ignore
			    cssclass   : "editable-table",
			    height     : "none",
			    width      : "none",
			    submitdata : function(value,setting) { return { select:value }; },
			    callback   : function(value, settings) { console.log(value); console.log(settings); $(this).text(value); },
		  	});
  		}
  	}

值没有变也会提交一次,有点浪费资源,修改代码,只有值改变的时候才能提交,核心代码是:

"onsubmit": function (settings, original) {
    if (original.revert.trim() == $('input',this).val().trim()) {
        original.reset();
        return false;
    }
}

完整如下:

    $(document).on("mouseover","td.editable",editable_input);
  	
  	function editable_input()
  	{
  		var $editable_type = $(this).attr('editable_type');
  		if($editable_type == 'text' || $editable_type == 'textarea')
  		{
			$(this).editable(BASEPATH + "/editable", { 
			    indicator  : '<img src="'+BASEURL+'public/assets/indicator.gif" />',
			    type       : $editable_type,
			    submit     : "OK",
			    cancel     : "Cancel",
			    onblur     : "cancel", //ignore
			    cssclass   : "editable-table",
			    height     : "none",
			    width      : "none",
			    onsubmit   : function (settings, original){
			    	if(original.revert.trim()==$('input',this).val().trim()){original.reset();return false;}},
			    submitdata : function(value,setting) { return { select:value }; },
			    callback   : function(value, settings) { console.log(value); console.log(settings); $(this).text(value); },
		  	});
  		}
  	}

 

 

本文:jQuery: 只有改变值才能提交 jeditable only submit if changed

Loading

Add a Comment

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.