[英]Table content based on URL content
I have written a piece of JavaScript so that when a user hovers over a specific piece of text in an a website, this pops up with a table. 我已经编写了一段JavaScript,以便当用户将鼠标悬停在网站中的特定文本上时,会弹出一个表格。
Currently the tables content is hard coded with a couple of words for debugging purposes, and it appears as as desired. 当前,为了调试目的,表的内容已经用几个单词进行了硬编码,并且可以根据需要显示。
The content html looks like - 内容html看起来像-
<tr>
<th>Name</th>
<th>Age</th>
</tr>
<tr>
<td>Jambo</td>
<td>22</td>
</tr>
So the tables content shows the aforementioned. 因此表内容显示了上述内容。
I now want to make the content of the table based on the content of a report that is viewed by accessing a URL. 我现在想基于通过访问URL查看的报告的内容来制作表的内容。
I did try this - 我确实尝试过-
<tr>
<td><a href="url">Link text</a></td>
</tr>
But of course this only provides a link to the report and not actually opens the content. 但是,当然,这仅提供指向报表的链接,而实际上并未打开内容。
How can I do this? 我怎样才能做到这一点?
An absolute horrendous but quick way of doing this would be: 绝对可怕但快速的方法是:
- Ajax Request your url Ajax索取您的网址
- Get table data with html tags as ajax responseText 使用html标记获取表数据作为ajax responseText
- document.getElementById(' yourmouseoverdivid ').innerHTML = responseText document.getElementById(' yourmouseoverdivid '). innerHTML = responseText
Another better way would be: 另一个更好的方法是:
- Using ajax fetch you table data as json 使用ajax将表数据作为json提取
- Create nested tabular html elements using javascript and the fetched json Eg: document.createElement('table') 使用javascript和获取的json创建嵌套的表格html元素, 例如:document.createElement('table')
- Append those elements to document.getElementById(' yourmouseoverdivid ') 将这些元素追加到document.getElementById(' yourmouseoverdivid ')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.