Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/149.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 改变;添加到收藏夹“中”;来自<;tr>;至<;t车身>;_Javascript_Html_Jquery - Fatal编程技术网

Javascript 改变;添加到收藏夹“中”;来自<;tr>;至<;t车身>;

Javascript 改变;添加到收藏夹“中”;来自<;tr>;至<;t车身>;,javascript,html,jquery,Javascript,Html,Jquery,我得到了一堆书的代码,这些书的每一个tr上都有最喜欢的按钮 这是我得到的密码 $(函数(){ $('tr')。单击(函数(e){ const$parentTable=$(this).closest(“表”); $(this.find('img.white star').toggle(); $(this.find('img.yellow star').toggle(); 常量$favs=$(“tr”).has('img.黄星:可见'); $parentTable.prepend($favs) c

我得到了一堆书的代码,这些书的每一个tr上都有最喜欢的按钮

这是我得到的密码

$(函数(){
$('tr')。单击(函数(e){
const$parentTable=$(this).closest(“表”);
$(this.find('img.white star').toggle();
$(this.find('img.yellow star').toggle();
常量$favs=$(“tr”).has('img.黄星:可见');
$parentTable.prepend($favs)
const favs=$favs.find(“td:first”).map((i,fav)=>$(fav.data(“id”)).get();
//localStorage.setItem($parentTable.attr(“id”)+“favs”,JSON.stringify(favs));//在服务器上取消对此的注释
})
让favs//=localStorage.getItem($(“.ratingTable”).attr(“id”)+“favs”);//在服务器上取消注释
//favs=favs?JSON.parse(favs):[];//在服务器上取消注释
favs=favs?JSON.parse(favs):[“Book A”,“Book C”];//测试后删除此项
$。每个(fav,功能(i,fav){
$(“表tr td[data id='“+fav+'”]){
$(this).parent()触发器(“单击”)
});
});
});
td{
光标:指针;
}
img{
高度:25px;
}
.隐藏{
显示:无;
}

道尔顿的魔法
约翰的椅子
C册

您需要将td更改为tbody everywhere

换成这个

 $("table tbody[data-id='" + fav + "']").each(function() {
注意:每个tbody中不能有一个以上的内容,所有tbody必须在同一个表中

  • $(“.fav”)。在(“单击”,单击它)
    更改为
    const$tbody=$(e.target)。最近的(“tbody”)
  • 删除地图中的
    find(“tbody”)
  • 需要恢复
完整代码

const clickIt=(e)=>{
const$tbody=$(e.target).最近的(“tbody”);
console.log($tbody.data(“id”))
const$parentTable=$tbody.closest(“表”);
$tbody.find('img.white star').toggle();
$tbody.find('img.yellow star').toggle();
常量$favs=$(“tbody”).has('img.黄星:可见');
$parentTable.prepend($favs)
常量favs=$favs.map((i,fav)=>$(fav.data(“id”)).get();
//localStorage.setItem($parentTable.attr(“id”)+“favs”,JSON.stringify(favs));//在服务器上取消对此的注释
};
$(函数(){
$('.fav')。单击(clickIt)
让favs//=localStorage.getItem($(“.ratingTable”).attr(“id”)+“favs”);//在服务器上取消注释
//favs=favs?JSON.parse(favs):[];//在服务器上取消注释
favs=favs?JSON.parse(favs):[“Video-A”,“Video-D”];//测试后删除此项
$。每个(fav,功能(i,fav){
$(“表tbody[数据id='“+fav+'”])。每个(函数(){
$(这个)。单击()
});
});
});
td{
光标:指针;
}
img{
高度:25px;
}
.隐藏{
显示:无;
}

视频-A:
日期:20年4月15日
长度:
类别:音乐
视频-B:
日期:20年4月15日
长度:
类别:音乐
视频-C:
日期:20年4月15日
长度:
类别:艺术
视频-D:
日期:20年4月15日
长度:
类别:舞蹈

您需要将td更改为tbody everywhere

换成这个

 $("table tbody[data-id='" + fav + "']").each(function() {
注意:每个tbody中不能有一个以上的内容,所有tbody必须在同一个表中

  • $(“.fav”)。在(“单击”,单击它)
    更改为
    const$tbody=$(e.target)。最近的(“tbody”)
  • 删除地图中的
    find(“tbody”)
  • 需要恢复
完整代码

const clickIt=(e)=>{
const$tbody=$(e.target).最近的(“tbody”);
console.log($tbody.data(“id”))
const$parentTable=$tbody.closest(“表”);
$tbody.find('img.white star').toggle();
$tbody.find('img.yellow star').toggle();
常量$favs=$(“tbody”).has('img.黄星:可见');
$parentTable.prepend($favs)
常量favs=$favs.map((i,fav)=>$(fav.data(“id”)).get();
//localStorage.setItem($parentTable.attr(“id”)+“favs”,JSON.stringify(favs));//在服务器上取消对此的注释
};
$(函数(){
$('.fav')。单击(clickIt)
让favs//=localStorage.getItem($(“.ratingTable”).attr(“id”)+“favs”);//在服务器上取消注释
//favs=favs?JSON.parse(favs):[];//在服务器上取消注释
favs=favs?JSON.parse(favs):[“Video-A”,“Video-D”];//测试后删除此项
$。每个(fav,功能(i,fav){
$(“表tbody[数据id='“+fav+'”])。每个(函数(){
$(这个)。单击()
});
});
});
td{
光标:指针;
}
img{
高度:25px;
}
.隐藏{
显示:无;
}

视频-A:
日期:20年4月15日
长度:
类别:音乐
视频-B:
日期:20年4月15日
长度:
类别:音乐
视频-C:
日期:20年4月15日
长度:
类别:艺术
视频-D:
日期:20年4月15日
长度:
类别:舞蹈
为什么需要