简体   繁体   English

错误:“期望标识符,而看到了'<'”

[英]Error: “Expected an identifier and instead saw '<'”

I am writing this in JS and trying to figure out what my editor is complaining about. 我正在用JS编写此文件,并试图弄清楚编辑器在抱怨什么。 Here is what I have: 这是我所拥有的:

document.write('<div id="email-widget"></div>');
  var widgetHTML = 
   <div id="email-widget-box">
    <div id="email-signup-form">
     <p><strong>Send deals directly to my inbox - Sign up now!</strong></p>

What is missing because my editor has 4 errors all for one line but I cannot figure this out. 遗漏了什么,因为我的编辑器在一行中全部有4个错误,但是我无法弄清楚。 The errors are: 错误是:

Expected an identifier and instead saw '<' 应为标识符,而看到的是“ <”
Missing semicolon 缺少分号
Expected an assignment or function call and instead saw an expression 需要一个赋值或函数调用,而是看到一个表达式
Missing semicolon 缺少分号

You start off just fine: 您刚开始就好:

var widgetHTML = 

what follows that = should be a Javascript expression. =应该是一个Javascript表达式。 Strings ( "..." ), numbers, variable names, function calls, any of those things combined with operators -- all would be fine. 字符串( "..." ),数字,变量名,函数调用,任何与运算符结合的东西-都可以。

But a bunch of HTML is not a Javascript expression. 但是一堆HTML 并不是 Java表达式。

<div id="email-widget-box">
 <div id="email-signup-form">
  <p><strong>Send deals directly to my inbox - Sign up now!</strong></p>

If you want to set widgetHTML to that HTML text, you'll need to make a string out of it: 如果要将widgetHTML设置widgetHTML HTML文本,则需要从中创建一个字符串:

var widgetHTML = '<div id="email-widget-box">' +
  '<div id="email-signup-form">' +
  '<p><strong>Send deals directly to my inbox - Sign up now!</strong></p>';

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

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