JS中通过方法名字符串调用
我贴:
<html>
<head>
<title>js中比如我有一个方法aa(),现在我只有这个方法的名字的字符串,那可以执行这个方法</title>
<script type="text/javascript">
var dd = "aa()";
var cc = "aa";
function aa()
{
alert();
}
function bb()
{
// 1
setTimeout(cc + "()",100);
// 2
var fun = eval(cc)
new fun();
// 3
eval(dd)
}
</script>
</head>
<body>
<input type="button" onclick="bb()" value="我点">
</body>
</html>