简体   繁体   English

解析错误:意外的令牌,应为“;” 在反应 JS

[英]Parsing error: Unexpected token, expected “;” in react JS

I am new to ReactJS.我是 ReactJS 的新手。 This is my first React Program.这是我的第一个 React 程序。 I have tried with some tutorials but it shows some errors.我已经尝试过一些教程,但它显示了一些错误。 I want to open popup windows in React I used below code to open popup windows but I am getting an error.我想在 React 中打开弹出窗口 windows 我使用下面的代码打开弹出窗口 windows 但出现错误。 Kindly fix the issue.请解决问题。 My code is given below:我的代码如下:

<html>
          <body>
            <div>
              <script>
              $(document).ready(function () {
              $("#OpenDialog").click(function () {
                  var w = window.open("", "popupWindow", "width=600, height=400, scrollbars=yes");
                  $w.html("<textarea></textarea>");
              });  // getting error here.
            });  // getting error here.

            </script>
            </div>
          <a id="OpenDialog" href="#">Click here to open dialog</a>
          <div id="dialog" title="Dialog Title">
            <p>test</p>
          </div>
          </body>
        </html>

Error is错误是

Parsing error: Unexpected token, expected "}"

                     //var $w = $(w.document.body);     
                     $w.html("<textarea></textarea>");  
               });
                 ^
               });
               </script>
            <a id="OpenDialog" href="#">Click here to open dialog</a>

I think you have wrong understanding of how react works, since you are using plain html to build what you are showing here.我认为您对 react 的工作原理有错误的理解,因为您使用普通的 html 来构建您在此处显示的内容。 First google "create react app", react uses JSX which is like combination of JS and Html, so you don't need to have script tags or html tags inside of your code, and you do not code inside of html file, you should be coding inside file that ends with js or jsx and you create as many of them as you want.首先谷歌“创建反应应用程序”,反应使用JSX,就像JS和Html的组合,所以你不需要在你的代码中有脚本标签或html标签,你不要在ZFC35FDC70D5FC69A53EZ文件内编码,你应该在以 js 或 jsx 结尾的文件中进行编码,您可以根据需要创建任意数量的文件。 It's best to have file for each bigger component, so your code is like pieces of legos and website is what you built with these legos.最好为每个更大的组件都有文件,这样你的代码就像乐高积木一样,而网站就是你用这些乐高积木构建的。

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

相关问题 反应:解析错误:意外的令牌,预期为“…” - React: Parsing error: Unexpected token, expected “…” 解析错误:意外的令牌,预期的“,” JavaScript React - Parsing error: Unexpected token, expected “,” JavaScript React 反应:解析错误:意外的令牌,预期的“,” - React: Parsing error: Unexpected token, expected “,” React - 解析错误:意外的令牌,预期的“;” - React - Parsing error: Unexpected token, expected “;” React Js:在 if else 语句中获取和错误行 50:20:解析错误:意外标记,预期“,” - React Js: Getting and error in if else statement Line 50:20: Parsing error: Unexpected token, expected "," 解析错误:意外的标记,预期的“,” - Parsing error: Unexpected token, expected "," React 组件'解析错误:意外的令牌,预期的“;”'渲染后 - React Component 'Parsing error: Unexpected token, expected “;”' after render 反应引导。 特别是解析错误:意外的标记,预期的“,” - React-Bootstrap. Specifically with Parsing error: Unexpected token, expected "," React组件构造函数(解析错误:意外令牌,期望“}”) - React component constructor (Parsing error: Unexpected token , expected “}”) React-Redux - 解析错误:意外的令牌,预期的“,”在行动创建者 - React-Redux - Parsing error: Unexpected token, expected “,” in action creator
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM