久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

    • <bdo id='Q6txK'></bdo><ul id='Q6txK'></ul>
  • <legend id='Q6txK'><style id='Q6txK'><dir id='Q6txK'><q id='Q6txK'></q></dir></style></legend>

        <i id='Q6txK'><tr id='Q6txK'><dt id='Q6txK'><q id='Q6txK'><span id='Q6txK'><b id='Q6txK'><form id='Q6txK'><ins id='Q6txK'></ins><ul id='Q6txK'></ul><sub id='Q6txK'></sub></form><legend id='Q6txK'></legend><bdo id='Q6txK'><pre id='Q6txK'><center id='Q6txK'></center></pre></bdo></b><th id='Q6txK'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='Q6txK'><tfoot id='Q6txK'></tfoot><dl id='Q6txK'><fieldset id='Q6txK'></fieldset></dl></div>

        <small id='Q6txK'></small><noframes id='Q6txK'>

      1. <tfoot id='Q6txK'></tfoot>
      2. 將字符串計(jì)算為 JavaScript 中的數(shù)學(xué)表達(dá)式

        Evaluating a string as a mathematical expression in JavaScript(將字符串計(jì)算為 JavaScript 中的數(shù)學(xué)表達(dá)式)
        • <tfoot id='LasXb'></tfoot>

            <small id='LasXb'></small><noframes id='LasXb'>

            <legend id='LasXb'><style id='LasXb'><dir id='LasXb'><q id='LasXb'></q></dir></style></legend>
            <i id='LasXb'><tr id='LasXb'><dt id='LasXb'><q id='LasXb'><span id='LasXb'><b id='LasXb'><form id='LasXb'><ins id='LasXb'></ins><ul id='LasXb'></ul><sub id='LasXb'></sub></form><legend id='LasXb'></legend><bdo id='LasXb'><pre id='LasXb'><center id='LasXb'></center></pre></bdo></b><th id='LasXb'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='LasXb'><tfoot id='LasXb'></tfoot><dl id='LasXb'><fieldset id='LasXb'></fieldset></dl></div>
              <bdo id='LasXb'></bdo><ul id='LasXb'></ul>

                  <tbody id='LasXb'></tbody>
                • 本文介紹了將字符串計(jì)算為 JavaScript 中的數(shù)學(xué)表達(dá)式的處理方法,對大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  如何在不調(diào)用 eval(string) 的情況下解析和評估字符串中的數(shù)學(xué)表達(dá)式(例如 '1+1')以產(chǎn)生其數(shù)值?

                  How do I parse and evaluate a mathematical expression in a string (e.g. '1+1') without invoking eval(string) to yield its numerical value?

                  在這個(gè)例子中,我希望函數(shù)接受 '1+1' 并返回 2.

                  With that example, I want the function to accept '1+1' and return 2.

                  推薦答案

                  我最終選擇了這個(gè)解決方案,它適用于對正整數(shù)和負(fù)整數(shù)求和(對正則表達(dá)式稍作修改也適用于小數(shù)):

                  I've eventually gone for this solution, which works for summing positive and negative integers (and with a little modification to the regex will work for decimals too):

                  function sum(string) {
                    return (string.match(/^(-?d+)(+-?d+)*$/)) ? string.split('+').stringSum() : NaN;
                  }   
                  
                  Array.prototype.stringSum = function() {
                      var sum = 0;
                      for(var k=0, kl=this.length;k<kl;k++)
                      {
                          sum += +this[k];
                      }
                      return sum;
                  }
                  

                  我不確定它是否比 eval() 快,但由于我必須多次執(zhí)行該操作,因此運(yùn)行此腳本比創(chuàng)建大量 javascript 編譯器實(shí)例更舒服

                  I'm not sure if it's faster than eval(), but as I have to carry out the operation lots of times I'm far more comfortable runing this script than creating loads of instances of the javascript compiler

                  這篇關(guān)于將字符串計(jì)算為 JavaScript 中的數(shù)學(xué)表達(dá)式的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

                  相關(guān)文檔推薦

                  Browser waits for ajax call to complete even after abort has been called (jQuery)(即使在調(diào)用 abort (jQuery) 之后,瀏覽器也會(huì)等待 ajax 調(diào)用完成)
                  JavaScript innerHTML is not working for IE?(JavaScript innerHTML 不適用于 IE?)
                  XMLHttpRequest cannot load, No #39;Access-Control-Allow-Origin#39; header is present on the requested resource(XMLHttpRequest 無法加載,請求的資源上不存在“Access-Control-Allow-Origin標(biāo)頭) - IT屋-程序員軟件開發(fā)技術(shù)分
                  Is it possible for XHR HEAD requests to not follow redirects (301 302)(XHR HEAD 請求是否有可能不遵循重定向 (301 302))
                  XMLHttpRequest 206 Partial Content(XMLHttpRequest 206 部分內(nèi)容)
                  Restrictions of XMLHttpRequest#39;s getResponseHeader()?(XMLHttpRequest 的 getResponseHeader() 的限制?)
                    • <bdo id='7ZcXi'></bdo><ul id='7ZcXi'></ul>

                      • <i id='7ZcXi'><tr id='7ZcXi'><dt id='7ZcXi'><q id='7ZcXi'><span id='7ZcXi'><b id='7ZcXi'><form id='7ZcXi'><ins id='7ZcXi'></ins><ul id='7ZcXi'></ul><sub id='7ZcXi'></sub></form><legend id='7ZcXi'></legend><bdo id='7ZcXi'><pre id='7ZcXi'><center id='7ZcXi'></center></pre></bdo></b><th id='7ZcXi'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='7ZcXi'><tfoot id='7ZcXi'></tfoot><dl id='7ZcXi'><fieldset id='7ZcXi'></fieldset></dl></div>

                        1. <small id='7ZcXi'></small><noframes id='7ZcXi'>

                            <tbody id='7ZcXi'></tbody>
                          <legend id='7ZcXi'><style id='7ZcXi'><dir id='7ZcXi'><q id='7ZcXi'></q></dir></style></legend>

                          <tfoot id='7ZcXi'></tfoot>

                            主站蜘蛛池模板: 超碰在线人人干 | 久久久久国产精品一区 | 国产a区 | 久久婷婷香蕉热狠狠综合 | 欧美一级片在线观看 | 久草网址| 国产精品一区久久久久 | 欧美福利视频 | 成人二区 | 午夜视频在线观看网址 | 亚洲一区二区在线视频 | 欧美精品三区 | 日韩精品视频在线 | 国产男女视频网站 | 日本综合在线观看 | 成人网av| 欧美精品在线看 | 中文字幕在线精品 | 岛国午夜 | 成人激情视频免费观看 | 精品久久不卡 | 看一级黄色毛片 | 日韩一区二区在线视频 | 欧美做暖暖视频 | 亚洲三级在线观看 | 国产综合久久 | 成人福利电影 | 国产在线精品一区二区三区 | 美女黄色在线观看 | 精品久久精品 | 免费黄色网址视频 | 日韩高清国产一区在线 | 91高清视频在线观看 | 美国一级黄色片 | 久久免费视频在线 | 99精品国产一区二区青青牛奶 | 91香蕉视频在线观看 | 亚洲手机在线 | 夜夜夜久久 | 天天干夜夜拍 | 日本久久网 |