Javascript 如何在单击项目时获取警报中的新闻\u id
如何在项目点击时获取项目ID,我可以在列表视图中显示数据,我想点击项目显示我得到了特别的Javascript 如何在单击项目时获取警报中的新闻\u id,javascript,html,json,Javascript,Html,Json,如何在项目点击时获取项目ID,我可以在列表视图中显示数据,我想点击项目显示我得到了特别的新闻\u ID警报 这是我的HTML页面: <body> <div data-role="page" id="taxmanhomepage" data-theme="e"> <div data-role="header" data-position="fixed" data-tap-toggle="false" data-theme="e"> <h4 a
新闻\u ID
警报
这是我的HTML页面:
<body>
<div data-role="page" id="taxmanhomepage" data-theme="e">
<div data-role="header" data-position="fixed" data-tap-toggle="false" data-theme="e">
<h4 align="center">Taxmann Demo App</h4>
</div>
<div data-role="content" data-theme="e">
<a data-role="button" onclick="callservice()">Webservice</a>
Todays Headlines:
<div class="content-primary">
<ul id="newlist" data-role="listview" data-inset="true"data-filter-theme="e" data-divider-theme="e">
</ul>
</div>
</div>
</div>
</body>
Taxmann演示应用程序
”;
}
$(“#新列表”)。追加(”;
$('#newlist')。列表视图('refresh');
$('#newlist').children('li').on('click',function(){
var index=$(this.index();
//var text=$(this.text();
警报(索引);
});
}
});
}
将新闻\u id
作为li
项的数据属性
,然后检索它:
$("#newlist").append("<li data-news-id='" + news_id + "' rest of string");
$('#newlist').children('li').on('click', function (){
var news_id = $(this).attr('data-news-id');
alert(news_id);
});
像这样更改代码中的附加部分
$("#newlist").append($("<li/>").data("newsId", news_id).html("<a href='#' ><h1 class='myHeader'>" + news_title + "</h1><br/><h6 class='myHeader'>" + news_short_description + "</h6></a>"));
$('#newlist').on('click', 'li',function () {
var index = $(this).index();
//var text = $(this).text();
alert($(this).data("newsId"));
});
你不是已经问过这个问题了吗?是的,我问过了,但有点不同,但现在我可以在这里应用项目点击功能,问题是如何在项目点击中获得提醒的新闻id删除副本:但我不想在列表视图中显示新闻id,我必须只显示新闻标题和新闻显示描述这不是康斯坦丁的观点ed out…读他的答案。测试代码!@user2372154我更新了一个建议,其中属性不可见。
$("#newlist").append($("<li/>").data("newsId", news_id).html("<a href='#' ><h1 class='myHeader'>" + news_title + "</h1><br/><h6 class='myHeader'>" + news_short_description + "</h6></a>"));
$('#newlist').on('click', 'li',function () {
var index = $(this).index();
//var text = $(this).text();
alert($(this).data("newsId"));
});