一个实现把公式中的变量进行任意替换的JS

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

ExpandedSubBlockEnd.gif        }

InBlock.gif        
if(a1 == "")
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
var t = arr[j];
InBlock.gif            a1 
= "innerHTML"+t;
ExpandedSubBlockEnd.gif        }

InBlock.gif        
//alert(newV)
InBlock.gif
        newV=newV+a1;
ExpandedSubBlockEnd.gif    }

InBlock.gif    alert(newV);
ExpandedBlockEnd.gif}

None.gif
</ script >

转载于:https://www.cnblogs.com/TV9/archive/2006/11/04/549632.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值