gpt4 book ai didi

javascript - 如何在 html cordova android 应用程序中创建 'add to favourite' 功能?

转载 作者:行者123 更新时间:2023-11-27 23:03:23 25 4
gpt4 key购买 nike

我正在使用 phonegap 创建歌本应用。在 index.html 中,我在 li 标签中有歌曲列表。当我点击一首特定歌曲时,它会在另一个本地 html 文件中打开该特定歌曲的歌词。

我想添加一个“收藏按钮”。单击收藏夹按钮后,我希望将该特定歌曲添加到收藏夹列表中。当用户打开收藏页面时,它应该显示他们喜欢的歌曲列表,当他们在收藏页面中单击一首歌曲时,它应该打开该特定歌曲的歌词 html 页面。

我是 HTML 的中级用户和 JavaScript 的初学者。

请帮我完成这个,

提前致谢。

最佳答案

因为这是一个“相当广泛”的问题,所以很难找到答案,但我建议做一个数组,将最喜欢的歌曲存储在其中,然后当你打开 favorites.html 页面时,它获取数组,并将信息写入页面。

例如当点击歌曲页面上的收藏夹按钮时,它会显示:歌曲名称(exampleSong)、歌曲页面(exampleSong.html)以及您需要的其他随机详细信息,然后转到 favorites.html 应该获取读取数组并写入页面的文档就绪函数。

抱歉,如果我帮不了那么多,但这是一个非常广泛的问题。

如果你需要帮助,这里有一些我创建的例子

(获取收藏夹数组,并将它们打印出来)

var favorites = [
["ExampleSong", "exampleSong.html"],
["LorddirtCoolSong", "LorddirtCoolSong.html"],
["StackOverflowIsAwesome", "StackOverflowIsAwesome.html"]
];

var containerA = document.getElementById("favoritesA");
for (var i in favorites)
{

for (var j in favorites[i])
{
var newElement = document.createElement("p");
newElement.innerHTML = favorites[i][j];
containerA.appendChild(newElement);
}
}

var containerB = document.getElementById("favoritesB");
for (var i in favorites)
{
var newElement = document.createElement("p");
newElement.innerHTML = "<h4>Favorite Song " + i + "</h4>";
containerB.appendChild(newElement);
for (var j in favorites[i])
{
var newElement = document.createElement("p");
newElement.innerHTML = favorites[i][j];
containerB.appendChild(newElement);
}
}

var containerC = document.getElementById("favoritesC");
for (var i in favorites)
{
var newElement = document.createElement("p");
newElement.innerHTML = "<h4>Favorite Song " + i + "</h4>";
containerC.appendChild(newElement);
for (var j in favorites[i])
{
if(j == 1){
}else{
var newElement = document.createElement("p");
newElement.innerHTML = "<a href='" + favorites[i][1] + "'>" + favorites[i][j] + "</a>";
containerC.appendChild(newElement);
}
}
}
.favoriteSongs{
border: 2px solid black;
display: block;
}
<!--
EXAMPLE 1A: Print out the Favorites
-->
<hr>
<h2>Example 1A: Print favorites out</h2>
<div id='favoritesA' class='favorites'>
</div>
<hr>
<!--
EXAMPLE 1B: Now you know the order of the songs!
-->
<h2>Example 1B: Print favorites out with formatting</h2>
<div id='favoritesB' class='favorites'>
</div>
<hr>
<!--
EXAMPLE 1C: Link them
-->
<h2>Example 1C: Link to the page</h2>
<div id='favoritesC' class='favorites'>
</div>
<hr>

非常不言自明,它获取最喜欢的歌曲数组,带有名称和 url,获取容器,即 <div id='favorites'></div>并将内容写入其中。

(哦,等等,我刚刚注意到我花了这么长时间在这上面哈哈哈。)示例:

1A:我所做的只是搜索数组收藏夹,然后打印出数组中的每一项。简单。

1B:略有不同,和上一个一样,但是我加了一个<h4>在数组中的每个数组之前标记。 (是的,数组中的数组中的数组令人困惑)。

1C: 不是打印出数组里面的两个数组,而是在数组中打印出数组里面的第一个东西,然后在数组中添加一个指向数组里面第二个东西的链接。已经糊涂了吗?通读一遍,您就会明白。

关于javascript - 如何在 html cordova android 应用程序中创建 'add to favourite' 功能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51257840/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com