在做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: 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: # Insert a new person # Replace an existing person # Generates: Element.replace("person_45", "-- Contents of partial --"); Source: show | on GitHub 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: 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 |