js中将字符串作为函数名来调⽤的⽅法⽅法:eval()
eg:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>将字符串作为函数名调⽤函数</title>
</head>
<body>
<span>指标:</span>
<select id="zhibiao">
<option selected="" value="总体">总体</option>
<option value="queryManagementVolume">办理量</option>
<option value="queryTimeConsuming">平均耗时</option>
<option value="queryOvertimePercent">超时占⽐</option>
</select>
</body>
<script src="../js/jquery.js"></script>
<script>
$(document).on("change",'select#zhibiao',function(){
var fn=$(this).val();
/* fn(); */
字符串函数title作用eval(fn+"()");
});
function queryManagementVolume(){
console.log("查询办理量");
}
function queryTimeConsuming(){
console.log("查询平均耗时");
}
function queryOvertimePercent(){
console.log("查询超时占⽐");
}
</script>
</html>
var slideArr=new Array(
'slideLeft',
'slideTop',
'slideRight',
'slideBottom',
'slideLeftTop',
'slideTopRight',
'slideRightBottom',
'slideBottomLeft'
)
;
function slideRandom(arr=slideArr,width,height,time) {
var length=slideArr.length;
var index=Math.floor(Math.random()*length);
var functionName=slideArr[index];
//alert(functionName);
eval(functionName+'(width,height,time)');
}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。