如何将onload添加到span元素

4

I have a function called loadXMLDoc which takes text from the url parameter and sets it inside the parameter name of another page that has the same span name. im trying to use onload to make it into one line by using onload instead of having it in 2 lines.

<span id="span number1" onload="loadXMLDoc('www.url.com','span number1')"></span>

<span id="span number1"></span>
<script> loadXMLDoc("www.url.com","span number1");</script>
1个回答

3

这是不可能的。 onload 只能在外部资源(图像、框架等)和 body 标签本身上使用。

根据您的页面结构,您可以将 onload="loadXMLDoc('www.url.com','span number1')" 添加到 <body> 标签中。否则,您的第二个示例看起来正确,并且也应该有效。


1
我在哪里可以找到支持onload的完整对象列表?或者有没有一些属性可以触发每个对象的异步更新,比如项目可用性。 - a s
https://www.w3schools.com/jsref/event_onload.asp - xerostomus

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接