哟社区!这里可能需要一些见解.. :) 我正在学习一些更高级的 js 概念。我正在运行这段代码,但结果没有像我预期的那样显示出来……我看不到错误……知道吗?谢谢!
<script type="text/javascript">
(function() {
var results, queue = [];
this.assert = function(pass, msg) {
var type = pass ? "PASS" : "FAIL";
var str = "<li class='" + type + "'><b>" +
type + "</b> " + msg + "</li>";
if ( queue )
queue.push( str );
else
results.innerHTML += str;
};
window.addEventListener("load", function() {
results = document.getElementById("results");
results.innerHTML = queue.join('');
queue = null;
});
// calling assert but it's not showing up the <li> with the message....( why? )
assert( true, "I always pass!" );
})();
</script>