如何将元素追加到弹出窗口

时间:2012-10-05 17:04:54

标签: javascript jquery

我正在尝试在弹出窗口中添加更多数据并设置我的表格样式。

我有

 var popup = window.open("popup.html", "popup","width=800","height=600");
     popup.document.write(
     "<table id='dataTable'>"+
      "<tr><th>test1</th><th>test2</th><th>test3<th></th>test4</th><th>test5</th></tr>" +
      "</table>");

ajax callback data
    codes....

如何附加数据并设置我的表格样式?

2 个答案:

答案 0 :(得分:2)

使用$("#dataTable",popup.document)在弹出窗口中显示您的表格:

var popup = window.open("popup.html", "popup","width=800","height=600");
     popup.document.write(
     "<table id='dataTable'>"+
     "<tr><th>test1</th><th>test2</th><th>test3<th></th>test4</th><th>test5</th></tr>" +
     "</table>");

$("#dataTable",popup.document)
     .css("border","1px solid red") // append CSS
     .append("<tr><td>append</td></tr>"); //append HTML

Here is the demo

答案 1 :(得分:0)

$('#dataTable').append(<your html>);
$('#dataTable').css({'style1':'value1', 'style2':'value2'});