[問題] javascript執行問題
<script>
var calculate_sqrt_patt=
/\(Math.sqrt\(\d+\)\)/g;
var metPatt;
calculate_sqrt_patt.compile(calculate_sqrt_patt);
var
CurrentResult="(Math.sqrt(121))+(Math.sqrt(25))+(Math.sqrt(81))+(Math.sqrt(144))+(Math.sqrt(169))+(Math.sqrt(49))";
while((metPatt=calculate_sqrt_patt.exec(CurrentResult))!=null)
{
var replaceString;
var str=metPatt.toString();
alert(CurrentResult+":\n"+str);
replaceString=eval(str).toString();
CurrentResult=CurrentResult.replace(str,replaceString);
}
/*
(Math.sqrt(121))+(Math.sqrt(25))+(Math.sqrt(81))+(Math.sqrt(144))+(Math.sqrt(169))+(Math.sqrt(49)):
(Math.sqrt(121))
11+(Math.sqrt(25))+(Math.sqrt(81))+(Math.sqrt(144))+(Math.sqrt(169))+(Math.sqrt(49)):
(Math.sqrt(81))
11+(Math.sqrt(25))+9+(Math.sqrt(144))+(Math.sqrt(169))+(Math.sqrt(49)):
(Math.sqrt(169))
*/
</script>
想請問為啥結果是跳著換的?
謝謝
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 118.160.179.238
討論串 (同標題文章)
完整討論串 (本文為第 1 之 2 篇):