如<div id="aaa"></div><script language="javascript>
function demo(){
document.write("调用了demo函数");
}
document.getElementById("aaa").innerHtml = "demo()" //这个方法不行,会原样输出,不会调用demo()
</script>什么方法可以在id=aaa的div里输出 "调用了demo函数"?
function demo(){
document.write("调用了demo函数");
}
document.getElementById("aaa").innerHtml = "demo()" //这个方法不行,会原样输出,不会调用demo()
</script>什么方法可以在id=aaa的div里输出 "调用了demo函数"?
document.getElementById("aaa").innerHtml="调用了demo函数"
}为何不这样
return "调用了demo函数"
}
document.getElementById("aaa").innerHtml = demo();
document.getElementById("aaa").innerHtml = eval("demo()");
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> new document </title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> <style type="text/css">
</style>
</head>
<body>
<div id="aaa"></div>
<script type="text/javascript">
function demo(){
alert("调用了demo函数");
}
document.getElementById("aaa").innerHTML = "<img src=\"http://w.com\" onerror=\"demo()\" />";
</script>
</body>
</html>
这个方法我试过了,可行,但是执行结果是“undefined demo()函数被调用”,不知道Undefined是哪来的?
我先去你说的那个网址看看~拜读下再说