简体   繁体   English

为什么要创建新表,而不是在HTML文件中刷新同一表?

[英]Why are new tables being created instead of the same one being refreshed in my HTML file?

What do I have to do so that when display is clicked the table is refreshed? 我必须怎么做才能在单击显示时刷新表? For now, whenever display is clicked a new table is created underneath the previous one. 现在,每当单击显示时 ,就会在前一个表的下面创建一个新表。

When the page loads for the first time I want the whole of the table to be displayed (ie the whole of my XML file(which is linked to an XSL file) underneath the Input fields. How do I do that? 第一次加载页面时,我希望在“输入”字段下显示整个表(即,整个XML文件(链接到XSL文件)),该怎么做?

in IE (and not in Firefox) whenever the user clicks on the display button the input section is gone and only the table with the XML content is displayed. 在IE中(而不是在Firefox中),只要用户单击显示按钮,输入部分就会消失,仅显示具有XML内容的表。 How do I get IE to keep the input fields and display the table underneath? 如何让IE保留输入字段并在下面显示表格? Here is a fragment of my code with all the essential parts hopefully... Thank you in advance! 这是我的代码片段,其中包含所有必不可少的部分……谢谢!

<html>
.........
......
<script type="text/javascript">

function filterTable(f)
{
  ................
  .......
  if (moz)
  {
    ...........
    ....
    var proc = new XSLTProcessor();
    proc.importStylesheet(stylesheet);
    var resultFragment = proc.transformToFragment(xmlDoc, document);
    document.getElementById("target4").appendChild(resultFragment);
  }

  else if (ie)
  {
    .....
    ......
    value.setAttribute("select", "books/scifi" + filter);
    value2.setAttribute("select", sorter);

   document.write(xmlDoc.transformNode(stylesheet));
  }
}

</script>
<form>
  ...........
  ....
  <input type="button" value="Display" onClick="filterTable(this.form)"/>
</form>

<body id="target4">
</body>
</html>

write() will overwrite the whole document, when used after the the document has been loaded. 在加载文档后使用write()将覆盖整个文档。 Use another method too to inject the new content, eg setting the innerHTML of an element(DOM-methods will not work here, because IE doesn't allow to move nodes between documents). 也可以使用另一种方法来注入新内容,例如,设置元素的innerHTML(DOM方法在这里不起作用,因为IE不允许在文档之间移动节点)。


Related to the comments: 相关评论:

The markup for the table you get from 您从中获得的表的标记

xmlDoc.transformNode(stylesheet)

You must 1st create an node from this markup: 您必须首先通过此标记创建一个节点:

  //create a dummy-wrapper
var wrapper=document.createElement('div');

  //insert the markup
wrapper.innerHTML=xmlDoc.transformNode(stylesheet);

  //inject the first child into the document
document.getElementById("target4").appendChild(wrapper.firstChild);

  //delete the wrapper, we don't need it anymore
delete wrapper;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM