87,993
社区成员
发帖
与我相关
我的任务
分享
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<script type="text/javascript">
</script>
<script type="text/javascript">
function aa(函数名,函数参数,函数体)
{
在第一个script创建一个加法的函数,并alert结果
}
aa(函数名,函数参数,函数体);
</script>
<body>
</body>
</html>
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<script>
function a(){alert("AA");}
function d(){alert("DD");}
</script>
<script>
// 自定义函数向后插入
function insertAfter( newElement, targetElement)
{
var parent = targetElement.parentNode;
if ( parent.lastChild == targetElement )
{
// 如果最后的节点是目标元素,则直接添加。因为默认是最后
parent.a( newElement );
}
else
{
//如果不是,则插入在目标元素的下一个兄弟节点的前面。也就是目标元素的后面
parent.insertBefore( newElement, targetElement.nextSibling );
}
}
var script_0 = document.getElementsByTagName("script")[0];
alert(script_0.innerHTML);
alert(script_0.innerHTML.indexOf("(\"AA\");}"));
var br = document.createElement("br");
var sp = script_0.innerHTML.split("(\"AA\");}");
alert(sp[0]);
//script_0.innerHTML =script_0.innerHTML+"function b(){alert(\"BB\");}";
script_0.innerHTML =sp[0]+"(\"AA\");}"+"function b(){alert(\"BB\");}"+sp[1];
alert(script_0.innerHTML);
eval(script_0.innerHTML);
alert("ab开始执行了");
a();
b();
function aa(函数名,函数参数,函数体)
{
window[函数名] = new Function(函数参数,函数体);
}
aa("funname","x","return x*x");
alert(funname(9));
function ada(funname,parameters,fbody)
{
window[funname] = new Function(parameters,fbody);
}
ada("ff1","x,y","return x+y");
alert(ff1(1,2));
</script>
</body>
</html>
function aa(函数名,函数参数,函数体)
{
window[函数名] = new Function(函数参数,函数体);
}
aa("funname","x","return x*x");
alert(funname(9));
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<script>
function a(){alert("AA");}
a();
</script>
<script>
var script_0 = document.getElementsByTagName("script")[0];
alert(script_0.innerHTML);
script_0.innerHTML =script_0.innerHTML+"function b(){alert(\"BB\");}";
alert(script_0.innerHTML);
b();
</script>
</body>
</html>
这么写为什么无效?