English 中文(简体)
使用以 Javascramp unat 表示的数据解析的“ 服务器” 数据在 html 表格中添加行=“ 服务器”
原标题:Add rows to html table using data parsed by Javascript runat="server"

I am having a little problem here. I have a <script language ="JavaScript" runat="server"> code that reads a table from a website, parses data and stores it in a 2-D array. It works correctly; I can display the data using Response.Write.

现在,我想用数组中的数据来构建我自己的表格,并在浏览器中显示。我想我只补充:

</head> 
<body onload="tableCreator();">
<table id="table" border="1">
    <tr> 
    <td id="Document Number">Document Number</td>
    <td id="Document Link">Document Link</td>
    <td id="Date Filed">Date Filed</td>
    <td id="Date Entered">Date Entered</td>
    <td id="Date Terminated">Date Terminated</td>
    <td id="Description">Description</td>
    </tr>
</table> 
<body> 
</html>

脚本结尾之后, 但这是开始出现问题的地方 。 我不知道要在哪里插入 < code> ableCreator () 函数 。 如果在代码( 手写语言 = "JavaScript" runat= "server" ) 中( 为了能够使用数组数据), 函数不会被调用 。 当我将标记更改为( 手写语言 = "JavaScript" (没有 runat= "server")) 时, 函数被调用, 但是脚本没有运行( 我有多个响应. write and nothing, 但表格正在打印中) 。

function tableCreator () {
  var table = document.getElementById("table");
  var rowCount = table.rows.length;
  var row;
  row = table.insertRow(rowCount);
  var cell1 = row.insertCell(0);
  cell1.innerHTML = "1";
}

有什么想法吗?

最佳回答

您混淆了服务器端代码和客户端代码 。

JavaScript 无法访问服务器上创建的 2d 数组( 添加 < code> runat= " server" 给您添加 < code> stript 标签不会允许您访问服务器边变量 ) 。 您需要用服务器边语言对数组进行序列排序, 然后再让客户端访问( 隐藏字段将对此有效 ) 。

或者,如果您有数据服务器边,为什么创建表格客户端。只要在页面加载时创建表格服务器边即可。

问题回答

暂无回答




相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签