如何在列表视图上执行onclick事件。如果我单击任何列表项,则需要警报,因为它是各自的值。这可能吗?这是我的代码
$("#select-choice").on('change', function(event) {
$("#locationList").empty();
var catg = this.value;
var db = window.sqlitePlugin.openDatabase({name: "MYDB"});
db.transaction(function (tx) {
tx.executeSql("select Location from Locationlog WHERE Category = '"+catg+"';", [], function (tx, res) {
var optionheading = '<li value="Select Location">Select Location</li>';
$("#locationList").append(optionheading);
for (var i = 0; i < res.rows.length; i++) {
var opt = '<li value="';
opt += res.rows.item(i).Location;
opt += '">';
opt += res.rows.item(i).Location;
opt += '</li>';
$("#locationList").append(opt);
}
$("#locationList").listview('refresh');
});
});
});
我正在尝试使用以下代码,但是它不起作用。任何建议,
$('#locationList > li').click(function(e){
alert($(this).attr('value'));
});
HTML:
<ul data-role="listview" id="locationList" name="locationList" data-inset="true">
<li value="Select Location">Select Location</li>
</ul>
最佳答案
$('#locationList > li').click(function(e){
alert($(this).attr('value'));
});
See JSFiddle