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

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

    1. <i id='k1rz8'><tr id='k1rz8'><dt id='k1rz8'><q id='k1rz8'><span id='k1rz8'><b id='k1rz8'><form id='k1rz8'><ins id='k1rz8'></ins><ul id='k1rz8'></ul><sub id='k1rz8'></sub></form><legend id='k1rz8'></legend><bdo id='k1rz8'><pre id='k1rz8'><center id='k1rz8'></center></pre></bdo></b><th id='k1rz8'></th></span></q></dt></tr></i><div id='k1rz8'><tfoot id='k1rz8'></tfoot><dl id='k1rz8'><fieldset id='k1rz8'></fieldset></dl></div>

      <tfoot id='k1rz8'></tfoot>
    2. JavaScript 字符串和数字转换

      时间:2023-10-12
    3. <tfoot id='daHcP'></tfoot>

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

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

                  <tbody id='daHcP'></tbody>

              • 本文介绍了JavaScript 字符串和数字转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                如何在 JavaScript 中执行以下操作?

                How can I do the following in JavaScript?

                1. 将1"、2"、3"连接成123"

                1. Concatenate "1", "2", "3" into "123"

                将123"转换为123

                Convert "123" into 123

                加 123 + 100 = 223

                Add 123 + 100 = 223

                将223转换为223"

                Covert 223 into "223"

                推荐答案

                你想熟悉 parseInt()toString().

                在您的工具包中有用的是查看变量以找出它是什么类型—typeof:

                And useful in your toolkit will be to look at a variable to find out what type it is—typeof:

                <script type="text/javascript">
                    /**
                     * print out the value and the type of the variable passed in
                     */
                
                    function printWithType(val) {
                        document.write('<pre>');
                        document.write(val);
                        document.write(' ');
                        document.writeln(typeof val);
                        document.write('</pre>');
                    }
                
                    var a = "1", b = "2", c = "3", result;
                
                    // Step (1) Concatenate "1", "2", "3" into "123"
                    // - concatenation operator is just "+", as long
                    //   as all the items are strings, this works
                    result = a + b + c;
                    printWithType(result); //123 string
                
                    // - If they were not strings you could do
                    result = a.toString() + b.toString() + c.toString();
                    printWithType(result); // 123 string
                
                    // Step (2) Convert "123" into 123
                    result = parseInt(result,10);
                    printWithType(result); // 123 number
                
                    // Step (3) Add 123 + 100 = 223
                    result = result + 100;
                    printWithType(result); // 223 number
                
                    // Step (4) Convert 223 into "223"
                    result = result.toString(); //
                    printWithType(result); // 223 string
                
                    // If you concatenate a number with a 
                    // blank string, you get a string    
                    result = result + "";
                    printWithType(result); //223 string
                </script>
                

                这篇关于JavaScript 字符串和数字转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:在&lt;input type=“number"&gt;中允许2位小数 下一篇:如何在 html 正文中显示 javascript var

                相关文章

                最新文章

              • <tfoot id='I1ktx'></tfoot>

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

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