Javascript 循环调用的函数中的switch语句
我在循环中使用函数时遇到了一个问题,该函数包含一个switch语句,它会分解代码(字面意思),因为switch语句包含breakJavascript 循环调用的函数中的switch语句,javascript,jquery,Javascript,Jquery,我在循环中使用函数时遇到了一个问题,该函数包含一个switch语句,它会分解代码(字面意思),因为switch语句包含break function presentation(input, fixedid) { switch(fixedid) { case 1: output = namesplice(input); break; case 6: output = str_rem
function presentation(input, fixedid)
{
switch(fixedid)
{
case 1:
output = namesplice(input);
break;
case 6:
output = str_remain(input, '0123456789');
break;
case 8:
output = str_replace(' ', '', strtoupper(input));
break;
case 11:
output = str_remain(input, '0123456789');
break;
default:
output = input;
break;
}
return output;
}
for (i=1;i<=cellCount;i++)
{
label = $('#cell0_'+ i).html();
for (j=1;j<=count(targetcolumns);j++)
{
if (jQuery.inArray(strtolower(label), sub[targetcolumns[j] + '_label']) >= 0)
{
result = $('#content'+ i).html();
result = presentation(result, j);
$('#result'+ j).append(result);
}
}
}
函数表示(输入,fixedd)
{
开关(fixedid)
{
案例1:
输出=名称策略(输入);
打破
案例6:
输出=str_剩余(输入'0123456789');
打破
案例8:
输出=str_replace(“”,,,strtoupper(输入));
打破
案例11:
输出=str_剩余(输入'0123456789');
打破
违约:
输出=输入;
打破
}
返回输出;
}
对于(i=1;i不,它没有
函数中的break
语句仅中断开关,不影响调用函数的代码的程序流
循环中可能存在的任何问题(问题中不清楚),并不是因为在函数内部使用了break
。出错是什么意思?第一个循环的中断在这里意味着什么?发生了什么?应该发生什么?是否实际定义了count
、strtolower
和所有其他函数?看起来有点像PHP和JavaScript的混合体函数,即附加到div的id为result1的结果是一个相同值的无止境链。所有其他函数都已定义并工作。我使用PHPjs,因此与PHP相似。当我直接调用函数表示,因此不在循环中,它工作得很好。“无止境”chain意味着你有一个无限循环,但是代码会挂起,永远不会显示值。当你运行代码时会发生什么,有多少值?在JSFIDLE上做一个例子时,我发现问题是str_replace函数,在某些组合中,它似乎打破了循环。问题来自str_replace f我太渴望与新事物合作了!