gpt4 book ai didi

javascript - 将 json 值作为链接放入列表中

转载 作者:行者123 更新时间:2023-11-28 00:08:16 24 4
gpt4 key购买 nike

我正在使用phonegap开发移动应用程序。这里我试图将我的数据库值显示到我的html页面中名为nextpage.html的列表中。但我无法将其作为链接插入。您能帮我将其作为链接插入吗?当我单击这些链接时,它将在新页面中显示该特定数据的详细信息。

nextPage.html

  <!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1, maximum-scale=1">

<link rel="stylesheet" href="css/jquery.mobile-1.4.4.min.css" />
<script src="js/jquery-1.11.1.min.js"></script>
<script src="js/jquery.mobile-1.4.4.min.js"></script>
<script src="js/nextPage.js"></script>
<title>Edfutura1</title>
</head>
<center>
<body id="category_id">
<div data-role="page" id="catlist">
<div id="loading" > </div>
<div data-role="header" data-position="fixed" data-theme="b">
<h1>category</h1>
</div>
<div data-role="main" class="ui-content">

<form id="nextForm" >
<ul data-role="listview" data-inset="true" id="category">

<li>
</li>
</ul>


</form>

</div>

</div>
</body>
</center>
</html>

nextPage.js

   var base_url="http://dev.edfutura.com/nithin/jps/edfuturaMob/";  
$(document).on("pageinit","#catlist", function() {


var submitUrl = base_url+"categorylist/get_categorylist";


//$("#loading").css("display", "block");


$.ajax({
url: submitUrl,
dataType: 'json',
type: 'POST',
success: function(response)
{

var categoryList = $('#category');
var category;
for(var i = 0, len = response.length; i < len; i++)
{

//pls do something
category = response[i];
categoryList.append($('<li>').attr('id', category.category_id).html(category.category_name));


}

},
error: function()
{
alert("error");

}

});
});

category_idcategory_name 是我的数据库值。我想通过单击来了解“category_name”的详细信息。我没有这样做。请帮助我...我的输出是

enter image description here

最佳答案

您可以在 li 元素内添加 anchor 标记:

var a = $('<a>').attr('href', '#').html(category.category_name);
categoryList.append($('<li>').attr('id', category.category_id).append(a));

关于javascript - 将 json 值作为链接放入列表中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31149308/

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