简体   繁体   中英

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. This happens when the user clicks on an item.

The attribute gets added to the body tag, but nothing happens. 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).

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');
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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