我想在a中添加一系列<li>元素<ul>,并以编程方式为每个元素添加一个click事件.
我不知道如何做到这一点,至少不是以一种简洁的jQueryish方式.
这是我现有的代码:
<ul id="saved-list"></ul>
<script type="text/javascript">
$.each(all_objects, function() {{
var list_route = "<li><a href='#saved-route'>" + this.text + "</a></li>";
$('#saved-list').append(list_route);
// add unique id (this.id) to item and click event here?
// pseudocode - onclick: alert(this.id);
});
$('#saved-list').refresh('listview'); // jquery mobile list refresh
</script>
Run Code Online (Sandbox Code Playgroud)
请有人建议如何以编程方式将click事件添加到每个列表项?
更新:我需要为每个列表项做一些略微不同的事情(让我们只是说一个提醒) - 道歉没有说清楚.