Use JavaScript to prevent a later `[removed]` tag from being evaluated?

前端 未结 7 698
北海茫月
北海茫月 2020-12-13 04:24

This is a bit of an oddball use case, but I have my reasons:

I\'d like to be able to write



        
相关标签:
7条回答
  • 2020-12-13 05:04

    As far as I know, you can't. If the markup looks like

    <script type="text/javascript" src="first.js"></script>
    <script type="text/javascript" src="second.js"></script>
    

    you can't access the second script element from within first.js, as it hasn't been added to the DOM at the moment the first script runs (even not if you assign an id to the second element). It doesn't matter whether the code of second.js is put inline or in an external file.

    The only thing I don't understand is your second point. First you say that you can't control the markup of the document, but then you state it is possible to load second.js dynamically (using AJAX).

    0 讨论(0)
提交回复
热议问题