我无法清除两个输入之一
我无法清除名称输入 当我进入严格模式控制台时说:“无法在字符串''上创建属性'值'”
const number = document.getElementById("number").value;
const name = document.getElementById("name").value;
console.log(name)
console.log(number)
if (name.trim() && number.trim()) {
let contact = {
name,
number
};
renderContact(contact);
console.log(contacts);
contacts.push(contact)
}
// clearInput(number, name);
this.name.value = '';
this.number.value = '';
};
i cant clear name input
when i go into strict mode console say: "Cannot create property 'value' on string ''"
const number = document.getElementById("number").value;
const name = document.getElementById("name").value;
console.log(name)
console.log(number)
if (name.trim() && number.trim()) {
let contact = {
name,
number
};
renderContact(contact);
console.log(contacts);
contacts.push(contact)
}
// clearInput(number, name);
this.name.value = '';
this.number.value = '';
};
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的“名字”和“号码”不是 DOM 元素。他们的价值观是:“你好,世界”等等。 String 是原始类型,不能在严格模式下在原型中定义属性。
};
Your "name" and "number" is not DOM elements. There's their values like: "Hello, World" and other. String is primitive type and you can't define properties in prototype in strict mode.
};