如何在没有JQuery生成的代码的情况下返回HTML

时间:2013-12-20 00:33:00

标签: javascript jquery html ajax

我正在使用JQuery的html()方法在我的页面上获取div的HTML。但是它返回一个包含所有JQuery生成的代码的字符串:

<ul><li id="fact_1" class="jstree-open"><ins class="jstree-icon">&nbsp;</ins><a><ins class="jstree-icon">&nbsp;</ins>Factory 1: (1-1000)</a><ul id="fact_1_children"><li class="jstree-leaf"><ins class="jstree-icon">&nbsp;</ins>348</li><li class="jstree-leaf"><ins class="jstree-icon">&nbsp;</ins>813</li><li class="jstree-leaf"><ins class="jstree-icon">&nbsp;</ins>447</li><li class="jstree-leaf"><ins class="jstree-icon">&nbsp;</ins>112</li><li class="jstree-last jstree-leaf"><ins class="jstree-icon">&nbsp;</ins>277</li></ul></li><li id="fact_2" class="jstree-open"><ins class="jstree-icon">&nbsp;</ins><a><ins class="jstree-icon">&nbsp;</ins>Factory 2: (1001-2000)</a><ul id="fact_2_children"><li class="jstree-leaf"><ins class="jstree-icon">&nbsp;</ins>1833</li><li class="jstree-leaf"><ins class="jstree-icon">&nbsp;</ins>1142</li><li class="jstree-leaf"><ins class="jstree-icon">&nbsp;</ins>1038</li><li class="jstree-leaf"><ins class="jstree-icon">&nbsp;</ins>1245</li><li class="jstree-leaf"><ins class="jstree-icon">&nbsp;</ins>1891</li><li class="jstree-leaf"><ins class="jstree-icon">&nbsp;</ins>1532</li><li class="jstree-last jstree-leaf"><ins class="jstree-icon">&nbsp;</ins>1741</li></ul></li><li id="fact_3" class="jstree-open"><ins class="jstree-icon">&nbsp;</ins><a><ins class="jstree-icon">&nbsp;</ins>Factory 3: (2001-3000)</a><ul id="fact_3_children"><li class="jstree-leaf"><ins class="jstree-icon">&nbsp;</ins>2895</li><li class="jstree-leaf"><ins class="jstree-icon">&nbsp;</ins>2974</li><li class="jstree-leaf"><ins class="jstree-icon">&nbsp;</ins>2120</li><li class="jstree-leaf"><ins class="jstree-icon">&nbsp;</ins>2230</li><li class="jstree-leaf"><ins class="jstree-icon">&nbsp;</ins>2854</li><li class="jstree-last jstree-leaf"><ins class="jstree-icon">&nbsp;</ins>2413</li></ul></li><li id="fact_4" class="jstree-open"><ins class="jstree-icon">&nbsp;</ins><a><ins class="jstree-icon">&nbsp;</ins>Factory 4: (3001-4000)</a><ul id="fact_4_children"><li class="jstree-leaf"><ins class="jstree-icon">&nbsp;</ins>3495</li><li class="jstree-leaf"><ins class="jstree-icon">&nbsp;</ins>3951</li><li class="jstree-last jstree-leaf"><ins class="jstree-icon">&nbsp;</ins>3931</li></ul></li><li id="fact_5" class="jstree-open jstree-last"><ins class="jstree-icon">&nbsp;</ins><a><ins class="jstree-icon">&nbsp;</ins>Factory 5: (4001-5000)</a><ul id="fact_5_children"><li class="jstree-leaf"><ins class="jstree-icon">&nbsp;</ins>4969</li><li class="jstree-leaf"><ins class="jstree-icon">&nbsp;</ins>4645</li><li class="jstree-last jstree-leaf"><ins class="jstree-icon">&nbsp;</ins>4517</li></ul></li></ul>

我需要获取一个只包含原始HTML的字符串,如下所示:

<ul id="tree"><li id="fact_1" class="jstree-open"><a>Factory 1: (1-1000)</a><ul id="fact_1_children"><li>348</li><li>813</li><li>447</li><li>112</li><li>277</li></ul></li><li id="fact_2" class="jstree-open"><a>Factory 2: (1001-2000)</a><ul id="fact_2_children"><li>1833</li><li>1142</li><li>1038</li><li>1245</li><li>1891</li><li>1532</li><li>1741</li></ul></li><li id="fact_3" class="jstree-open"><a>Factory 3: (2001-3000)</a><ul id="fact_3_children"><li>2895</li><li>2974</li><li>2120</li><li>2230</li><li>2854</li><li>2413</li></ul></li><li id="fact_4" class="jstree-open"><a>Factory 4: (3001-4000)</a><ul id="fact_4_children"><li>3495</li><li>3951</li><li>3931</li></ul></li><li id="fact_5" class="jstree-open"><a>Factory 5: (4001-5000)</a><ul id="fact_5_children"><li>4969</li><li>4645</li><li>4517</li></ul></li></ul>

有没有办法做到这一点?这是事先。

1 个答案:

答案 0 :(得分:1)

如果您在修改HTML之前将HTML存储到var,您将在以后使用它。