区段标签是否有类似onload的内容?

我想做类似的事情:

<section id="{{flasklist[1]}}" onload="$('#exp{{flasklist[0]}}').click()">

But it has no effect. Separately, I know the action $('#exp{{flasklist[0]}}').click() works as intended, its just not being triggered. Im fairly limited, because the page and section are being called with window.open() so I can't follow that with anything. Is there a way to do this without restructuring the whole site?

评论
  • 景长星
    景长星 回复

    No. Only things with URLs get load events (with the onload attribute on the <body> element representing the load event for the whole document).

    如果要在DOM中添加HTML块后立即运行一些JS:只需在其后放置一个script元素。

    <section id="{{flasklist[1]}}">
    </section>
    <script>
        $('#exp{{flasklist[0]}}').click()
    </script>
    
  • Peter
    Peter 回复

    我将在该部分中编写一个脚本标签,然后将js放在其中

    <section><script>$('#exp{{flasklist[0]}}').click()</script></section>