我有一个包含以下属性的html表:
In [1]: from bs4 import BeautifulSoup
In [2]: l = [
"""text1 <a href="http://example.com">hello, world</a> text2""",
"""text1 <a href="http://example.com" onclick="javascript:alert('<b>text2</b>')">hello, world</a> text3"""
]
In [3]: for s in l:
soup = BeautifulSoup(s, "html.parser")
link = soup.a
print(link["href"] + "\t" + link.get_text())
...:
http://example.com hello, world
http://example.com hello, world
我需要一个jquery函数来使用循环动态创建同一个表。任何帮助表示赞赏
答案 0 :(得分:1)
这是解决方案。
您只需要使用jquery clone方法。然后,您必须append到div
。
for(var i = 0; i < 10; i++){
$('div').append($('table').eq(0).clone());
//or this: $('div').append($('table:first').clone());
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<h1 id="tableTitle"></h1>
<div style="overflow-x: auto; white-space: nowrap; height:305px">
<table id="render_${pluginId}" border="1" style="width: 100%" class="testRunTable">
<tr>
<th id="tableHeader">Test Types</th>
<th id="tableHeader"># of Tests</th>
<th id="tableHeader"># of Approved <br> Test Designs</br></th>
<th id="tableHeader"># Executed</th>
<th id="tableHeader"># Passed</th>
<th id="tableHeader">% Executed</th>
<th id="tableHeader">% Passing <br> (of Executed)</th>
<th id="tableHeader"># Blocked</th>
<th id="tableHeader"># Failed</th>
<th id="tableHeader"># Defects<br> Opened</br> </th>
<th id="tableHeader"># Defects<br> Resolved</br></th>
<th id="tableHeader"># Technical<br> Debt</br> </th>
</tr>
</table>
</div>
答案 1 :(得分:0)
获取表格clone()并将其添加到您的页面。
示例:
for (var i = 0; i < 10; ++i) {
$('body').append($('#tableTitle').clone());
}