在我的网络应用程序中,我的函数中有以下代码。当我在 Firefox 中执行代码时,它工作正常并给出输出。但是当我在 chrome 中执行相同的代码时,该函数进入无限循环并返回(它不会抛出任何异常或错误)。
信息: 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 中警报不断出现。它不执行前两行,最后两行只是执行警报,而且也连续执行。
信息:这在 Chrome 版本 47 上运行良好,但在更新后现在在版本 49 中不起作用。
请帮忙解释为什么 Chrome 会出现这种奇怪的行为。
最佳答案
我不久前遇到了一个相关问题,我通过在调用后编写函数的定义来解决它
关于javascript - 代码在 Firefox 中运行良好,但在 Chrome 中不起作用。为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36246548/