jquery添加并添加
如何使用jquery添加
?
问题是我的表有1或2行?
$('#myTable tr:has(th)').wrap('');
1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4
您需要做的是删除行并将它们附加到thead元素
var myTable = jQuery("#myTable"); var thead = myTable.find("thead"); var thRows = myTable.find("tr:has(th)"); if (thead.length===0){ //if there is no thead element, add one. thead = jQuery("").appendTo(myTable); } var copy = thRows.clone(true).appendTo("thead"); thRows.remove();
jsFiddle exmaple
使用wrapAll而不是wrap
$('#myTable tr:has(th)').wrapAll(''); $("#myTable thead").prependTo("#myTable")
function createTable(data) { var str = ""; str += ''; str += 'Pos Ref '; for (var item in data.recentList) { str += ''; for (idata in data.recentList[item]) { str += '' + data.recentList[item][idata] + ' '; } str += ' '; } str += '
'; $('body').append(str); }
从数组创建表的工作版本
- 如何使用jQuery检查文本框中的值是否为素数
- 错误:拒绝访问属性“处理程序”的权限
- jQuery UI Slider – 禁用单击滑块轨道
- 如何在$ .ajax()的成功函数中加载Javascript文件?
- 使用jQuery延迟或承诺等待多个$ .post调用完成
- 在React JS中创建元素
- onChange回调没有在React组件中触发
- onbeforeunload等待ajax结果
- 尝试通过单击jquery幻灯片中的链接图像来更新页面的#content div的内容
Interesting Posts