我有以下代码将用户输入的html / js动态加载到iframe中以执行它:
function compile(s)
{
s = '<!DOCTYPE html><html><head><script type="text/javascript" src="jQuery/jquery-2.1.4.min.js"><\/script><\/head><body>' + s + '<\/body><\/html>';
document.getElementById("ifrm").src = "data:text/html;charset=utf-8," + escape(s);
}
$(document).ready(function(){
compile("<script>$(document).ready(function(){console.log('lol');});<\/script><p>Test<\/p>");
});
使用此代码,我收到错误消息 Uncaught ReferenceError:$未定义。发生了什么事?