代码在firefox中运行良好,但在chrome中不起作用.为什么?

Code is working fine in firefox but not working in chrome. Why?

本文关键字:chrome 但在 不起作用 为什么 firefox 运行 代码      更新时间:2023-09-26

在我的web应用程序中,我在一个函数中有以下代码。当我在firefox中执行代码时,它运行良好,并为我提供输出。但当我在chrome中执行相同的代码时,函数进入无限循环并返回(它不会抛出任何异常或错误)。

并且Info:elem是xml元素而不是html元素;xml是一个SVG图像

代码是这样的:

函数调用:

buildElemView(viewElement, container, 1, viewType);

然后函数:

function buildElemView(elem, container, start, viewType){
        var vwType = viewType;
        var cat = $(elem).find('cat:first').text();
                //alert("cat is "+cat);
        var type = $(elem).find('type:first').text();
        var id = $(elem).find('eid:first').text();
        var mid = $(elem).find('mid:first').text();
        var parentMids = $(elem).parents().map(function () {
              return $(this).find('mid:first').text();
            })
        .get().reverse().join("");
        if (viewType==1 && Number(eleCat>60) && Number(cat)<40)    
            return;
        var parentElementId = parentMids;
        var elementGroupId = parentMids+mid;
        var grp = $(elem).find('gr:first').text();
        var cz = $(elem).find('cz:first').text();
        var zo = $(elem).find('zo:first').text();
        var yo = $(elem).find('yo:first').text();

        var rotate = ($(elem).find('rt:first').text().split(';'))[0];
        var scale = ($(elem).find('sc:first').text().split(';'))[0];
        var positionx = ($(elem).find('px:first').text().split(';'))[0];
        var positiony = ($(elem).find('py:first').text().split(';'))[0];
        var positionz = ($(elem).find('pz:first').text().split(';'))[0];
        var dimension = $(elem).find('dm:first').text();
        var parentdimension = $(elem).parent().find('dm:first').text();
        var parentheight=0;
        if (parentdimension !='')
            parentheight = (parentdimension.split(';'))[2];
        if (parentheight==undefined || parentheight=="null")
            parentheight =0;
        var height = 0;
        if (dimension !='')
            height = (dimension.split(';'))[2];
        if (height==undefined || height=="null")
            height =0;

        var transformStr = "";
        var num =0;
        if (start && start==1)
        {
            transformStr= "translate(0,0) rotate(0) scale(1,1)";
            if (viewType==1 && Number(eleCat)<100) {
                var px = 0;
                var py = 0;
                if (scaleX==-1) px = 15000;
                if (scaleY==-1) py = 15000;
                transformStr = "translate("+ px+","+py +") rotate(0) scale("+ scaleX+","+scaleY+ ")";
            }
            if (Number(type)==50 || Number(type)==80 || Number(type)==100)
                vwType=4;
        }
        else {
            if (viewType<3 || Number(cat)>40)
                {
                   if (viewType==2) {
                       var px = positionx;
                       var py = positiony;
                       var pz = positionz;
                        if (parentheight)
                            positiony = Number(parentheight)-Number(positionz)-Number(height);
}

//And there is a lot of Code here but its not even executing the entire code //strightly coming to alert box after clicking debug stepover.
}

函数太大了,我只能给你这么多。。。

但通过调试,问题发生在这里。。。

var cat = $(elem).find('cat:first').text();
var type = $(elem).find('type:first').text();
var id = $(elem).find('eid:first').text();
var mid = $(elem).find('mid:first').text();

我在他们之间这样放了一条警告信息后得出了结论。

var cat = $(elem).find('cat:first').text();
var type = $(elem).find('type:first').text();
alert("Alert");
var id = $(elem).find('eid:first').text();
var mid = $(elem).find('mid:first').text();

在firefox中,警报显示一次,所有行都被执行并返回。但在铬报警是不断到来。它并没有执行前两行,最后两行只是执行警报,这太连续了

信息:这在chrome版本47中运行良好,但更新后在版本49中不起作用。

请帮助解释Chrome的这种奇怪行为。

我在一个月前遇到了一个相关的问题,我在调用后编写了函数的定义,解决了这个问题

相关文章: