灵感来自javascript论坛,经过自己的改进,应该说是比较完美了:
function yunsuan(a,op,b)
{
try
{
eval("result=" + a+ op + b);
return result;
}
catch(e)
{
alert("err");
}
}
function main()
{
var a,b,s;
a =prompt("please input a number?");
s = prompt("输入运算符");
b = prompt("please input another number?");
alert(yunsuan(a,s,b));
}