隨筆-167  評論-65  文章-0  trackbacks-0

          在做rails的無刷新的數據更新時,老是在replace 和 replace_html上出問題,當你遇到此問題時,不煩二者嘗試下看看,看了下rails API

          replace(id, *options_for_render)

          Replaces the "outer HTML" (i.e., the entire element, not just its contents) of the DOM element with the given id.

          options_for_render may be either a string of HTML to insert, or a hash of options to be passed to ActionView::Base#render. For example:
            # Replace the DOM element having ID 'person-45' with the
            # 'person' partial for the appropriate object.
            page.replace 'person-45', :partial => 'person', :object => @person

          This allows the same partial that is used for the insert_html to be also used for the input to replace without resorting to the use of wrapper elements.

          Examples:
            <div id="people">
              <%= render :partial => 'person', :collection => @people %>
            </div>

            # Insert a new person
            #
            # Generates: new Insertion.Bottom({object: "Matz", partial: "person"}, "");
            page.insert_html :bottom, :partial => 'person', :object => @person

            # Replace an existing person

            # Generates: Element.replace("person_45", "-- Contents of partial --");
            page.replace 'person_45', :partial => 'person', :object => @person

          Source: show | on GitHub
          replace_html(id, *options_for_render)

          Replaces the inner HTML of the DOM element with the given id.

          options_for_render may be either a string of HTML to insert, or a hash of options to be passed to ActionView::Base#render. For example:
            # Replace the HTML of the DOM element having ID 'person-45' with the
            # 'person' partial for the appropriate object.
            # Generates:  Element.update("person-45", "-- Contents of 'person' partial --");
            page.replace_html 'person-45', :partial => 'person', :object => @person

          Source: show | on GitHub

          從api中可以看出replace相當于  OuterHtml , replace_html相當于 InnerHtml,那么OuterHtml 和 InnerHtml有什么區別呢,大致解釋如下:

          innerHTML 設置或獲取位于對象起始和結束標簽內的 HTML
          outerHTML 設置或獲取對象及其內容的 HTML 形式
          innerText 設置或獲取位于對象起始和結束標簽內的文本
          outerText 設置(包括標簽)或獲取(不包括標簽)對象的文本

          innerText和outerText在獲取時是相同效果,但在設置時,innerText僅設置標簽內的文本,而outerText設置包括標簽在內的文本。

          ref:

          http://www.cnblogs.com/zpq521/archive/2008/07/12/1241493.html

          http://blog.csdn.net/lynnlin1122/archive/2008/09/09/2905442.aspx

          http://www.87cool.com/articleShow.aspx?number=52

          write by feng
          posted on 2009-04-15 18:44 fl1429 閱讀(818) 評論(0)  編輯  收藏 所屬分類: Rails
          已訪問數:
          free counters
          主站蜘蛛池模板: 永德县| 靖远县| 英吉沙县| 天气| 上林县| 咸丰县| 疏勒县| 台南市| 佛坪县| 永和县| 枞阳县| 甘孜县| 启东市| 鹰潭市| 伊宁市| 开鲁县| 阳城县| 海安县| 育儿| 广南县| 新余市| 南丰县| 西乌| 汕尾市| 云安县| 城市| 道真| 韶关市| 清水河县| 拜城县| 休宁县| 鲁甸县| 临汾市| 巴南区| 霍林郭勒市| 历史| 固始县| 仁寿县| 白河县| 南汇区| 抚州市|