Javascript setattribute doens';您不能更改内容文档吗?

Javascript setattribute doens';您不能更改内容文档吗?,javascript,html,Javascript,Html,我想动态更改对象的数据,但如果我执行以下操作,在日志中,a将是所需的具有数据源的对象,但a.contentDocument仍然是旧文档 window.onload = function () { // Get the Object by ID var a = document.getElementById("tangramObj"); a.setAttribute("data", files[file_count]); console.lo

我想动态更改对象的数据,但如果我执行以下操作,在日志中,a将是所需的具有数据源的对象,但a.contentDocument仍然是旧文档

window.onload = function () {
  // Get the Object by ID
  var a = document.getElementById("tangramObj");
  a.setAttribute("data", files[file_count]);
  console.log(a, a.contentDocument);
  // Get the SVG document inside the Object tag
  var svgDoc = a.contentDocument;
在index.html中定义的对象:

<object id="tangramObj" data="" type="image/svg+xml"></object>


在访问contentdocument之前,是否有任何方法可以保证设置了数据?

如何设置
a.setAttribute(“数据”)
应该更改
contentDocument
?这些属性不是完全独立的吗?我认为contentDocument是只读的,所以更改它的唯一方法是更改对象的数据并访问其contentDocument..您需要在更改数据属性后等待加载:
a.onload=function(){console.log](a.contentDocument);};