通过父项显示内容更改 [英] Displaying change of content through parent

查看:160
本文介绍了通过父项显示内容更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在fieldset中包含DHTML内容.这包括纯HTML,嵌套对象(甚至其他字段集)和inputselecttextarea对象的值更改.

I have DHTML content inside a fieldset. This includes plain html, nested objects (even other fieldsets), and value change of input, select, and textarea objects.

如果内容已更改,我想更改字段集的边框. 以下作品:

I'd like to change the border of the fieldset if the contents have been changed. The following works:

$('fieldset[name=qsfs127]').children('input').change(function(){
    $(this).parent('fieldset').css({border:'1px solid red'});
})

这处理输入;我可以将其扩展为选择和文本区域.

This handles the input; I can extend it to select and textarea.

问题:

  1. 如何对html进行更改?
  2. 是否可以通过将当前html()与存储的html()进行比较来完成所有这些更改跟踪?
  3. 如果(2)是,那么这将处理撤消"的情况吗?


我有一个按钮,可以ajax上载内容并保存更改.然后,我删除边框颜色


I have a button that ajax-uploads contents, and saves the changes. I then remove the border color

推荐答案

1.)您可以通过与jQuery

1.) You could track HTML changes in a similar way that the jQuery livequery plugin does. The livequery plugin wraps all of the jQuery DOM manipulation methods and when any of them are called, the wrapper method does something special and then proxies back to the original function. This will only work for the update/undo uses cases assuming the both use one of the jQuery DOM manipulation methods to change state.

$.each('append', 'prepend', 'after', 'before', 'wrap', 'attr', 'removeAttr', 'addClass', 'removeClass', 'toggleClass', 'empty', 'remove', 'html', function(i, funcName) {

   // Short-circuit if the method doesn't exist
   if (!$.fn[funcName]) return;

   // Save a reference to the original method
   var old = $.fn[funcName];

   // Create a new method
   $.fn[funcName] = function() {

      // Call the original method
      var r = old.apply(this, arguments);

      //Do something special here! Compare the stored html of the fieldset
      //to the new html state and update border accordingly

      // Return the original methods result
      return r;
   }
});

2.)您可以通过这种方式进行跟踪,似乎有点费劲.没有关于用例和数据控制的更多信息,很难推荐任何东西.

2.) You could keep track this way, seems a little heavy handed. Without more information about your use case and control of data it is hard to recommend anything.

3.)如果您确实将原始html()的值存储在字段集中,那么它似乎也适用于撤消情况.您也可以在撤消操作之后比较html()的值.但是,如果您要创建撤消"按钮,在我看来,您将需要具有所有更改的一些历史记录,并且一旦用户没有更多撤消,那么它们应该回到原始状态并且不能进行html()的比较. ).

3.) If you did store the value of the original html() in the fieldset it seems that it would work for the undo case as well. You could just compare the value of the html() after an undo as well. However if you are creating an "undo" button it seems to me that you will need to have some history of all changes, and once the user has no more undos then they should be back at the original state and no comparison of the html() should be needed.

这篇关于通过父项显示内容更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆