2012-09-28 26 views
0

我有一个JQuery的功能有点困难。由于我对这门语言非常不确定,我想知道是否有人可以提供帮助。jQuery的 - 与JavaScript变量斗争

$('.editableWC').editable('<?php echo base_url();?>ratesheet/editrowwendCall/<?=$editable['url'];?>/', 
     { 
     callback: function(value){ 
      $(this).data('bgcolor', $(this).css('background-color')); 
      if(value == this.revert) 
       {                    
       $(this).animate({ backgroundColor: "red", color: "white" }, 400); 
       $(this).animate({ backgroundColor: $(this).data('bgcolor'), color: "black" }, 400); 
       } 
      else 
       {                    
       $(this).animate({ backgroundColor: "green", color: "white" }, 400); 
       $(this).animate({ backgroundColor: $(this).data('bgcolor'), color: "black" }, 400); 
       } 
      }, 
     name : 'value', 
     style : 'display:inline; position:relative; right:120px;', 
     width : '100px', 
     height: '16px', 
     onblur : 'submit' 
    }); 

这是我的代码。它只是在php验证中检查已发布的项目,如果不符合验证则将其返回原始值,如果不符合验证则返回新值。

所以,代码应该看到,如果返回值是像原来一样,如果没有变化,显示出红色的不成功,或绿色为成功(如果值不同)。绿色确实有效,但它不会将原始值回传为与this.revert值相同。

该代码会发生什么,如果值不变=绿色 如果值改变并且符合验证=绿色 如果值改变,则不符合验证=根本没有动画。当它想闪红灯。

我会很感激的任何帮助,因为我完全出我的深度,当涉及到的JavaScript。

+0

检查什么的'this.revert'与'cosnole.log' – EaterOfCode

回答

1

试试这个:

$('.editableWC').editable('<?php echo base_url();?>ratesheet/editrowwendCall/<?=$editable['url'];?>/', 
    { 
    that:this, 
    callback: function(value){ 
     $(this.that).data('bgcolor', $(this.that).css('background-color')); 
     if(value == this.that.revert) 
      {                    
      $(this.that).animate({ backgroundColor: "red", color: "white" }, 400); 
      $(this.that).animate({ backgroundColor: $(this.that).data('bgcolor'), color: "black" }, 400); 
      } 
     else 
      {                    
      $(this.that).animate({ backgroundColor: "green", color: "white" }, 400); 
      $(this.that).animate({ backgroundColor: $(this.that).data('bgcolor'), color: "black" }, 400); 
      } 
     }, 
    name : 'value', 
    style : 'display:inline; position:relative; right:120px;', 
    width : '100px', 
    height: '16px', 
    onblur : 'submit' 
}); 
+0

你接近.. – EaterOfCode