日期:2014-05-16  浏览次数:20409 次

Js简单判断四则运算是否可用
function?test(s){?
????try{
????????return?!isNaN(eval("("+s+")"));
????}catch(e){
????????return?false;
????}
}
alert(test("1+6*(2+(3-1)/1+(9-5*1))"));
//--------------------------------------------------------------------------------------
<script>
var?str?=?"1+6*(2+(3-1)/1+(9-5*1))";
try{
????eval("var?ret?=?"+str);
????if(ret!=Infinity){
????????alert("right");
????}else{
????????alert("wrong");
????}
}catch(e){
????alert("wrong");