【发布时间】: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