svg #document加载事件

时间:2016-10-17 12:33:44

标签: javascript jquery html svg

我在find_item_request = client.factory.create('FindItemType') shape_types = client.factory.create('ns1:DefaultShapeNamesType') shape_type = client.factory.create('ns1:ItemResponseShapeType') shape_type.BaseShape = 'Default' find_item_request.ItemShape = shape_type find_item_request._Traversal = 'Shallow' mailbox = Element('ns1:Mailbox') emailaddress = Element('ns1:EmailAddress').setText('dries@myhost.be') mailbox.append(emailaddress) folder_id_type = client.factory.create('ns1:DistinguishedFolderId') folder_id_type.Mailbox = mailbox folder_id_type._Id = 'calendar' folder_ids = client.factory.create('ns1:NonEmptyArrayOfBaseFolderIdsType') folder_ids.DistinguishedFolderId = folder_id_type find_item_request.ParentFolderIds = folder_ids calendar_view = client.factory.create('ns1:CalendarViewType') calendar_view._StartDate = start calendar_view._EndDate = end find_item_request.CalendarView = calendar_view client.service.FindItem.method.soap.input.body.wrapped = False try: find_item_response = client.service.FindItem(find_item_request) except WebFault as e: raise e msg = result.FindItemResponseMessage 的数据属性中有SVG:

<object>

我动态更改数据属性的来源:

<html:figure id="imapc">
    <html:object type="image/svg+xml" id="imap"></html:object>
</html:figure>

当我尝试获取SVG DOM时:

this.svgobject = document.getElementsByTagName("object")[0];
this.svgobject.setAttribute("data", "lib/img/" + this.hash + ".svg");

我得到像这样的DOM

if("contentDocument" in this.svgobject) {
    this.svgdom = this.svgobject.contentDocument;
}

因为<html> <head></head> <body></body> </html> 尚未加载自己的DOM,但如果this.svgobject setTimeout if ("contentDocument" in this.svgobject) 100ms我正常this.svgdom

<svg>...</svg>

此SVG DOM是否有“已加载”事件等待?

1 个答案:

答案 0 :(得分:0)

尝试使用onload函数。

&#13;
&#13;
<svg width="200" height="200" xmlns="http://www.w3.org/2000/svg" onload='init(evt)'>
  <html:figure id="imapc">
      <html:object type="image/svg+xml" id="imap"></html:object>
  </html:figure>
  <script type="text/ecmascript">
    function init(evt) {
      alert('svg is ready');
      console.log('ready');
      var svgobject = document.getElementById("imap");
      svgobject.setAttribute("data", "lib/img/" + this.hash + ".svg");
    }
  </script>
</svg>
&#13;
&#13;
&#13;