繁体   English   中英

使用 console.log 或 document.write 将转换后的字符串显示为数字无效。 串联显示不工作也不工作

[英]Displaying converted string to number using console.log or document.write not working. Concatenation display not working not working either

我是 JS 和 HTML 的初学者,这个程序是为了更好地学习概念。 尝试用 3 种方式将字符串转换为数字的基本程序。 无法确定转换是否已经发生。 也无法显示两个此类转换后数字的串联。

错误在由 console.log 和 document.write 组成的行中抛出。 错误:未捕获的语法错误:非法字符

这里的问题是什么?

<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <title></title>
  </head>
  <body>
      <h6>Q3</h6>
    <script type="text/javascript">
      numstr = "456";
      let num1 = numstr – 0;
      let num2 = parseInt(numstr);
      let num3 = new Number(numstr);
      console.log(typeof(num1));
      console.log(typeof(num2));
      console.log(typeof(num3));

    </script>
<br>
    <h6>Q4</h6>
    <script type="text/javascript">
        var num = 123.789;
        num2 = parseInt( num );
        num3 = parseInt( num, 8);
        console.log(num2 + “:::” + num3);
        document.write(num2 + “:::” + num3);
     </script>
  </body>
</html>

我认为您是从某个文档中复制并粘贴的。 减去let num1 = numstr – 0; 不是减号,而是结束破折号。 也将“:::”中的引号替换为“:::”

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM