今天同事阿聪他需要实现一个把一个运算公式中的变量替换的功能,我就帮忙想一下,写了下面这么一个方法来测试,好像OK。
<
script type
=
"
text/javascript
"
>
![ExpandedBlockStart.gif](/Images/OutliningIndicators/ExpandedBlockStart.gif)
function
test()
{
var newV = "";
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
var arr;
var maths = ["+", "-", "*", "/", "(", ")" ];
var temp = "abc,+,bcd,*,(,cde,-,def,)-ttt/bv,";
arr = temp.split(",");
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
for(var j=0; j<(arr.length-1); j++)
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
var a1 = "";
for(var m=0; m<maths.length; m++)
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if(arr[j]==maths[m])
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
a1 = arr[j];
}
}
if(a1 == "")
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
var t = arr[j];
a1 = "innerHTML"+t;
}
//alert(newV)
newV=newV+a1;
}
alert(newV);
}
</
script
>