avascript的eval函数在IE11和chrome中不起作

avascript的eval函数在IE11和chrome中不起作

本文介绍了javascript的eval函数在IE11和chrome中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我有一个java脚本函数:



Hi All,

I have a java script function as:

<script type="text/javascript" >
 var FileTypeGroupValues1 = '<%= FileTypeGroupValues.ClientID %>';
            var GroupArr;
            var VariableRecord;
            FillFileTypeArray();
            function FillFileTypeArray() {

                var strFileTypeGroup = document.getElementById(FileTypeGroupValues1).value;
                var IE = document.all ? true : false;
                if (strFileTypeGroup != "") {
                    if (IE) {
                        window.execScript(strFileTypeGroup);
                    }
                    else {

                            GroupArr = eval(strFileTypeGroup);

                        }
                    }
                }
                alert(GroupArr.length );
            }
</script>





这里你可以把strFileTypeGroup的值=var GroupArr = new Array(); GroupArr [0 ] = '19~3'; GroupArr [1] ='19~4'; GroupArr [2] ='20~5'; GroupArr [3] ='20~6'; GroupArr [4] = '18~8 '; GroupArr [5] ='20~9'; GroupArr [6] = '19~10'; GroupArr [7] ='19~11'; GroupArr [8] ='17~12'; GroupArr [9] = '19~13'; GroupArr [10] = '20~14'; GroupArr [11] = '19~15'; GroupArr [12] = '18~16'; GroupArr [13] = '18~17' ; GroupArr [14] = '17~21'; GroupArr [15] ='20~22'; GroupArr [16] = '20~16'; GroupArr [17] ='8~28'; GroupArr [18] = '15~28'; GroupArr [19] ='0~31'; GroupArr [20] ='0~32'; GroupArr [21] ='0~33'; GroupArr [22] = '19~23'; GroupArr [23] ='0~41'; GroupArr [24] ='1~2'; GroupArr [25] ='0~42'; GroupArr [26] ='2~5'; GroupArr [27] =' 6~1'; GroupArr [28] ='4~1 ; GroupArr [29] ='0~43'; GroupArr [30] ='0~44';;



当我在IE7,8中运行此功能时,9,10和FireFox它给GroupArr.length = 31

但它在IE 11和chrome中给出了错误的结果。



请帮忙,我很难坚持这个问题。



谢谢&问候

Mohammad Wasif



here you can put value of strFileTypeGroup="var GroupArr = new Array();GroupArr[0] = '19~3';GroupArr[1] = '19~4';GroupArr[2] = '20~5';GroupArr[3] = '20~6';GroupArr[4] = '18~8';GroupArr[5] = '20~9';GroupArr[6] = '19~10';GroupArr[7] = '19~11';GroupArr[8] = '17~12';GroupArr[9] = '19~13';GroupArr[10] = '20~14';GroupArr[11] = '19~15';GroupArr[12] = '18~16';GroupArr[13] = '18~17';GroupArr[14] = '17~21';GroupArr[15] = '20~22';GroupArr[16] = '20~16';GroupArr[17] = '8~28';GroupArr[18] = '15~28';GroupArr[19] = '0~31';GroupArr[20] = '0~32';GroupArr[21] = '0~33';GroupArr[22] = '19~23';GroupArr[23] = '0~41';GroupArr[24] = '1~2';GroupArr[25] = '0~42';GroupArr[26] = '2~5';GroupArr[27] = '6~1';GroupArr[28] = '4~1';GroupArr[29] = '0~43';GroupArr[30] = '0~44';";

When I run this function in IE7,8,9,10 and FireFox it gives GroupArr.length=31
but it gives wrong results in IE 11 and chrome.

Please help, I am badly stuck in this problem.

Thanks & Regards
Mohammad Wasif

推荐答案

var cmd = "['19~3','19~4','20~5','20~6','18~8','20~9','19~10','19~11','17~12','19~13','20~14','19~15','18~16','18~17','17~21','20~22','20~16','8~28','15~28','0~31','0~32','0~33','19~23','0~41','1~2','0~42','2~5','6~1','4~1','0~43','0~44']";

var GroupArr = eval(cmd);

alert(GroupArr.length);


这篇关于javascript的eval函数在IE11和chrome中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 13:49