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

使用eval() 函数

    var page1 = 1;
    function ajax_getMsg(type){
        var type = type;
        alert('page'+type); //弹出 page1
        alert(eval('page'+type)); //弹出 page1的值 1;
        exit;

    }

猜你喜欢

转载自blog.csdn.net/qq_31238721/article/details/78250408