转自:https://zhidao.baidu.com/question/1733819401878068867.html
可以使用js的eval函数实现,示例如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
<script type=
"text/javascript"
>
//自定义函数,用于弹出三个参数的值
function
alertFunc(str1,str2,str3){
alert(str1);
alert(str2);
alert(str3);
}
//自定义函数:根据传入的函数名,调用函数
function
callAlert(functionName){
//根据函数名得到函数类型
var
func=eval(functionName);
//创建函数对象,并调用
new
func(arguments[1],arguments[2],arguments[3]);
}
</script>
<!--编写按钮,在点击事件中调用函数-->
<button onclick=
"callAlert('alertFunc','tom','hello','world')"
>测试函数调用</button>
|