我正在使用JQuery的html()
方法在我的页面上获取div的HTML。但是它返回一个包含所有JQuery生成的代码的字符串:
<ul><li id="fact_1" class="jstree-open"><ins class="jstree-icon"> </ins><a><ins class="jstree-icon"> </ins>Factory 1: (1-1000)</a><ul id="fact_1_children"><li class="jstree-leaf"><ins class="jstree-icon"> </ins>348</li><li class="jstree-leaf"><ins class="jstree-icon"> </ins>813</li><li class="jstree-leaf"><ins class="jstree-icon"> </ins>447</li><li class="jstree-leaf"><ins class="jstree-icon"> </ins>112</li><li class="jstree-last jstree-leaf"><ins class="jstree-icon"> </ins>277</li></ul></li><li id="fact_2" class="jstree-open"><ins class="jstree-icon"> </ins><a><ins class="jstree-icon"> </ins>Factory 2: (1001-2000)</a><ul id="fact_2_children"><li class="jstree-leaf"><ins class="jstree-icon"> </ins>1833</li><li class="jstree-leaf"><ins class="jstree-icon"> </ins>1142</li><li class="jstree-leaf"><ins class="jstree-icon"> </ins>1038</li><li class="jstree-leaf"><ins class="jstree-icon"> </ins>1245</li><li class="jstree-leaf"><ins class="jstree-icon"> </ins>1891</li><li class="jstree-leaf"><ins class="jstree-icon"> </ins>1532</li><li class="jstree-last jstree-leaf"><ins class="jstree-icon"> </ins>1741</li></ul></li><li id="fact_3" class="jstree-open"><ins class="jstree-icon"> </ins><a><ins class="jstree-icon"> </ins>Factory 3: (2001-3000)</a><ul id="fact_3_children"><li class="jstree-leaf"><ins class="jstree-icon"> </ins>2895</li><li class="jstree-leaf"><ins class="jstree-icon"> </ins>2974</li><li class="jstree-leaf"><ins class="jstree-icon"> </ins>2120</li><li class="jstree-leaf"><ins class="jstree-icon"> </ins>2230</li><li class="jstree-leaf"><ins class="jstree-icon"> </ins>2854</li><li class="jstree-last jstree-leaf"><ins class="jstree-icon"> </ins>2413</li></ul></li><li id="fact_4" class="jstree-open"><ins class="jstree-icon"> </ins><a><ins class="jstree-icon"> </ins>Factory 4: (3001-4000)</a><ul id="fact_4_children"><li class="jstree-leaf"><ins class="jstree-icon"> </ins>3495</li><li class="jstree-leaf"><ins class="jstree-icon"> </ins>3951</li><li class="jstree-last jstree-leaf"><ins class="jstree-icon"> </ins>3931</li></ul></li><li id="fact_5" class="jstree-open jstree-last"><ins class="jstree-icon"> </ins><a><ins class="jstree-icon"> </ins>Factory 5: (4001-5000)</a><ul id="fact_5_children"><li class="jstree-leaf"><ins class="jstree-icon"> </ins>4969</li><li class="jstree-leaf"><ins class="jstree-icon"> </ins>4645</li><li class="jstree-last jstree-leaf"><ins class="jstree-icon"> </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>
有没有办法做到这一点?这是事先。
答案 0 :(得分:1)
如果您在修改HTML之前将HTML存储到var
,您将在以后使用它。