JQuery $(document).ready() and [removed]()

前端 未结 4 1532
甜味超标
甜味超标 2020-12-12 17:50

Firstly, is there a way to use document.write() inside of JQuery\'s $(document).ready() method? If there is, please clue me in because that will re

4条回答
  •  一生所求
    2020-12-12 18:25

    With the requirements given, no, you can't use document.write without really hosing up the document. If you're really bent on not changing the code, you can override the functionality of document.write() like so and tack on the result later:

    var phbRequirement = "";
    
    $(function() {
      document.write = function(evil) {
        phbRequirement += evil;
      }
      document.write("Haha, you can't change my code!");
      $('body').append(phbRequirement);
    
    });
    

    Make sure you overwrite the document.write function before it is used. You can do it at anytime.

    The other answers are boring, this is fun, but very pretty much doing it the wrong way for the sake of fulfilling the requirements given.

提交回复
热议问题