我尝试创建模块化应用程序,因此每个页面都包含自己的HTML和JavaScript代码。 我打算像这样动态加载所有代码:
var s = document.createElement("script");
s.type = "text/javascript";
s.src='function oncl() { alert("click");}';
$(".selector").append(s);
$( ".selector" ).
append('<input type="button" onclick="ocl();" />
<form action="../test/test_upload4.php"
method="POST" enctype="multipart/form-data" name="getnamefile">
<input type="file" id="uploadfile" name="uploadfile">
<input type="submit" id="Submit" name= "Submit" value="Upload"></form>');
但是它不起作用 - 错误: ocl未定义。可能的原因是什么?如果我理解正确,每个网页都有一个包含所有JavaScript函数的对象 - 那么为什么不能添加或删除函数?