Evaluating a string as a mathematical expression in JavaScript

前端 未结 16 2396
我在风中等你
我在风中等你 2020-11-22 03:34

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?

<
16条回答
  •  清歌不尽
    2020-11-22 04:10

    Try AutoCalculator https://github.com/JavscriptLab/autocalculate Calculate Inputs value and Output By using selector expressions

    Just add an attribute for your output input like data-ac="(#firstinput+#secondinput)"

    No Need of any initialization just add data-ac attribute only. It will find out dynamically added elements automatically

    FOr add 'Rs' with Output just add inside curly bracket data-ac="{Rs}(#firstinput+#secondinput)"

提交回复
热议问题