2

在此脚本中,jsdom 不会调用 HTML 文档正文的 onLoad 属性中定义的函数。为什么不?

var testHTML = '<html> \n' +
'    <head> \n' +
'        <title>AJAX Testing</title> \n' +
'        <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.js"></script> \n' +
'        <script type="text/javascript"> \n' +
'            function loaded(){ \n' +
'                $("body").html("<p>AJAX was used to update the contents of this page!</p>"); \n' +
'            } \n' +
'        </script> \n' +
'    </head> \n' +
'    <body onLoad="loaded()"> \n' +
'        <p>No ajax work has been done</p> \n' +
'    </body> \n' +
'</html>';
var jsdom = require('jsdom');
var options = {
        features:{
          FetchExternalResources:['script']
        , ProcessExternalResources:['script']
        }
    }
var document = jsdom.jsdom(testHTML, null, options)
var window = document.createWindow();
console.log(window.document.innerHTML);
4

1 回答 1

0

尝试使用<body onload="loaded()">

于 2012-03-30T19:28:10.010 回答