【问题标题】:How to fix this "Syntax error:Unexpected identifier"?如何解决此“语法错误:意外的标识符”?
【发布时间】:2021-08-05 16:55:51
【问题描述】:

我正在尝试制作一个必须保存联系人号码和电话的 js 联系人应用程序,但我收到此错误“第 61 行的意外标识符”。

我不知道终点似乎在哪里,我该如何解决?这是我的代码:

class Contact {
    constructor(props) {
        this.state = {items:this.props.contacts};
        this.getContacts(); }
     getContacts = () => {
        fetch('http://dev.samples.com/getcontacts.php')
            .then(rsp=>rsp.json())
            .then(response =>{
                this.setState({items:response.data});
                console.log(response.data)
            })
    }
}
    this.setState({items:response.data});
     handleChange(e);
       if(e.target.name == 'name'){
           this.setState({currentContact : { name: e.target.value}})
       }
       if(e.target.name == 'email'){
           this.setState({currentContact : { email: e.target.value}})
       }
       if(e.target.name == 'phone'){
           this.setState({currentContact : { phone: e.target.value}})
       }
       if(e.target.name == 'notes'){
           this.setState({currentContact: {notes: e.target.value}});
       }
        if(e.target.name == 'id'){
            if(e.target.value != undefined || e.target.value != ''){
                this.setState({currentContact : { id: e.target.value}});
                console.log(e.target.value);
            }
        }
        class Prop {
        constructor(props){
        this.state = {currentContact: this.props.currentContact};
        this.currentContact = this.props.currentContact;
        this.id = this.props.currentContact.id;
        this.handleSubmit = this.handleSubmit.bind(this);
        this.handleChange = this.handleChange.bind(this);
    }
}
 function save() 
{ 
var x = button.SaveContact();
var y =  document.open("contact app.html"); 
x.save(contact.txt);
button.Save.appendChild(1);
} 
var Name='Stefan',
Phone="078345678"
function doSaveAs(){
    if (document.execCommand){
        document.execCommand("SaveAs")
    }
    else {
        alert("Save-feature available only in Internet 5.x.")
    }
}
function doSaveAs(button)
let g="Elton"
let p = "0767554433"
function save(g,p);

当我尝试保存联系人时,我也收到此错误

:"contact app.html?id={this.id}%2F&name=Stefan&phone=0785678901:31 Uncaught ReferenceError: doSave is not defined
?
    at HTMLInputElement.onclick (contact app.html?id={this.id}%2F&name=Stefan&phone=0785678901:31)"?

【问题讨论】:

  • 错误信息会准确地告诉您它遇到问题的行中的哪一行和字符。您在该行和字符位置看到了什么?
  • 什么是function doSaveAs(button) let g="Elton" let p = "0767554433" function save(g,p);
  • 你刚刚撤消了我的编辑.....
  • 嗨!当您提出问题时,文本区域右侧有一个橙色的大如何格式化框,其中包含有用的信息。还有一个工具栏,里面装满了格式化辅助工具。还有一个 [?] 按钮提供格式化帮助。 和一个预览区域,在文本区域和“发布您的问题”按钮之间显示您的帖子在发布时的样子(这样您就必须滚动过去才能找到该按钮,所以您d 看看它)。使您的帖子清晰,并表明您花时间这样做,可以提高您获得好答案的机会。
  • 下次TJ会知道的

标签: javascript xcode error-handling identifier unexpected-token


【解决方案1】:

并不是真正的 JavaScript 开发人员,但我认为您需要查看函数定义以及如何调用它们。原因是您似乎开始将 doSaveAs 定义为一个新函数,然后继续处理其他代码。可能期待随后的代码块。除此之外,我不知道你想要完成的范围。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-07-25
    • 1970-01-01
    • 2022-12-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多