js 拼接字符串 识别为变量 而不是字符串

来源:互联网 发布:利润表数据分析 编辑:程序博客网 时间:2024/06/16 01:30
使用eval() 函数

    var page1 = 1;
    function ajax_getMsg(type){
        var type = type;
        alert('page'+type); //弹出 page1
        alert(eval('page'+type)); //弹出 page1的值 1;
        exit;
    }
原创粉丝点击