Jquery html encode & decode

<script type="text/javascript">
                      $(document).ready(function(){
                        function htmlEncode(value){
                          //create a in-memory div, set it's inner text(which jQuery automatically encodes)
                          //then grab the encoded contents back out.  The div never exists on the page.
                          return $('<div/>').text(value).html();
                        }
                        function htmlDecode(value){
                          return $('<div/>').html(value).text();
                        }
                        $("div#content").html(htmlDecode("<{$theart[theart].content}>"));
                        console.log(htmlDecode("<{$theart[theart].content}>"));
                        // $("#content").html("<p>test</p>");
                      });
                    </script>

發佈了222 篇原創文章 · 獲贊 4 · 訪問量 14萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章