JavaScript新手-需要帮助使用表单中的数据创建多个对象吗
我刚开始学习JavaScript,现在已经被一个星期的作业困住了,我尝试了几种解决方案,但每次我添加一些东西,我就会破坏其他东西。 任务是创建一个表单(我已经完成了)。该表单用于输入新收藏夹项目的数据,当输入每个项目时,应在页面和控制台日志中显示该项目,当输入其他项目时,将其添加到列表中,并显示所有项目- 前收藏夹有:URL:,标题:O'Reilly School,注释:help,标签:School,learning,URL:,标题:Google,注释:使用Google查找JavaScript信息,标签:搜索,查找信息faves:html:133 具体说明是为所有收藏夹和每个新收藏夹项目使用对象。显示收藏夹的功能(在控制台和页面上)应包含在对象的方法中 我能够将表单中的数据转换成一个函数,并在昨天使用了创建收藏夹的函数,但不确定今天早上发生了什么 如果有人能看看这个,告诉我,如果我至少朝着正确的方向前进,我将不胜感激。我现在只是在兜圈子。(我在代码中有很多console.log语句,因此我可以尝试查看它在做什么)。 谢谢 代码:JavaScript新手-需要帮助使用表单中的数据创建多个对象吗,javascript,Javascript,我刚开始学习JavaScript,现在已经被一个星期的作业困住了,我尝试了几种解决方案,但每次我添加一些东西,我就会破坏其他东西。 任务是创建一个表单(我已经完成了)。该表单用于输入新收藏夹项目的数据,当输入每个项目时,应在页面和控制台日志中显示该项目,当输入其他项目时,将其添加到列表中,并显示所有项目- 前收藏夹有:URL:,标题:O'Reilly School,注释:help,标签:School,learning,URL:,标题:Google,注释:使用Google查找JavaScript信
//用于从web表单中创建收藏项的函数
函数FaveoriteEntry(url、标题、注释、标记){
console.log(“在Fave函数中”);
this.url=url;
log(this.url);
this.title=标题;
console.log(this.title);
this.comment=注释;
console.log(this.comment);
this.tags=标签;
console.log(this.tags);
console.log(“拥有所有项目”);
}
//函数从web表单检索数据并发送到函数以创建收藏夹
//反对。
函数addFavorite(){
var myFavorites=[];
console.log(“登录功能”);
var furl=getFavorites.formURL.value;
var ftitle=getFavorites.formTitle.value;
var fcomment=getFavorites.formComment.value;
var ftags=getFavorites.formTags.value;
this.clear=getFavorites.reset();
console.log(“条目:“+furl+”“+ftitle+”“+fcomment+”“+ftags”);
this.createFavorites=函数(url、标题、注释、标记){
console.log(“在Fave函数中”);
this.url=url;
log(this.url);
this.title=标题;
console.log(this.title);
this.comment=注释;
console.log(this.comment);
this.tags=标签;
console.log(this.tags);
console.log(“拥有所有项目”);
this.string=(this.url+”,“+this.title+”,“+this.comment+”,”+
这是"标签",;
myFavorites.push(this.string);
var addfavorite=新的this.createFavorites(furl、ftitle、fcomment、,
自由贸易协定);
console.log(myFavorites);
}
}
正文{
字体系列:Helvetica、Ariel、无衬线;
}
形式{
显示:表格;
边界间距:5px;
}
表格p{
显示:表格行;
}
表格标签{
显示:表格单元格;
文本对齐:右对齐;
}
表单输入{
显示:表格单元格;
}
评论{
字号:80%;
颜色:#777777;
}
span.tags{
字号:80%;
颜色:rgb(48,99,170);
}
高级JavaScript项目:收藏夹和标记
标记并保存您的收藏夹
添加新收藏夹:
网址:
标题:
评论:
标签:
收藏夹列表
试验-
把这句话:
var addfavorite = new this.createFavorites(furl, ftitle, fcomment,
ftags);
console.log(myFavorites);
createFavorites
函数的外侧。如下所示:
function addFavorite() {
var myFavorites = [];
console.log("In Function");
var furl = getFavorites.formURL.value;
var ftitle = getFavorites.formTitle.value;
var fcomment = getFavorites.formComment.value;
var ftags = getFavorites.formTags.value;
this.clear = getFavorites.reset();
console.log("Entry: " + furl + " " + ftitle + " " + fcomment + " " + ftags);
this.createFavorites = function(url, title, comment, tags) {
console.log("In Fave Function");
this.url = url;
console.log(this.url);
this.title = title;
console.log(this.title);
this.comment = comment;
console.log(this.comment);
this.tags = tags;
console.log(this.tags);
console.log("Have all items");
this.string = (this.url + "," + this.title + "," + this.comment + "," +
this.tags);
myFavorites.push(this.string);
}
var addfavorite = new this.createFavorites(furl, ftitle, fcomment,
ftags);
console.log(myFavorites); // result here
}
您正在调用
this.createFavorites
中的createFavorites
。你从来没有打过FavoriteEntry
(顺便说一句,里面有输入错误)。非常感谢!我将尝试一下,然后我可以开始研究显示的方法:)