简体   繁体   English

单击按钮后是否可以触发onLoad事件

[英]Is it possible to fire an onLoad event after a button is clicked

I want to fire an onLoad event after updating the body tag with additional attributes. 我想在使用其他属性更新body标签后触发onLoad事件。 This happens when the user clicks on an item. 当用户单击某个项目时,就会发生这种情况。

The attribute gets added to the body tag, but nothing happens. 该属性被添加到body标签,但是什么也没有发生。 How can I fix this? 我怎样才能解决这个问题?

$('#about-link').click(function () {
    $("body").attr("onLoad","outputXML('about-content', 'assets/xml/sample.xml', 'assets/xsl/sample.xsl');");
    onload();
});

Load events happen when a resource and its dependent resources have finished loading. 当资源及其从属资源完成加载时,发生加载事件。

If you want something to fire when a user clicks something, use a click (and/or touch and/or pointer) event instead, or (in your case) perhaps call the function in whatever code is adding the additional attributes to the body tag (which itself was probably triggered by one of these events). 如果您希望在用户单击某物时触发某物,请改用click(和/或触摸和/或指针)事件,或者(在您的情况下)用任何代码在body标签中添加其他属性的方式调用该函数(其本身可能是由这些事件之一触发的)。

I managed to figure it out. 我设法弄清楚了。 This works. 这可行。

$('#about-link').click(function () {
    window.showCorrectPage('#about', '#about-li');
    outputXML('about-content', 'assets/xml/sample.xml', 'assets/xsl/sample.xsl');
});

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

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