我有一个列表视图,它影响本地数据库中的数据。我想在列表项上添加和点击事件,所以我使用这个网站的点击示例http://www.raymondcamden.com/index.cfm/2012/5/23/Context-Menu-Example-with-jQuery-移动设备,但是当在模拟器上运行此代码时,它工作正常,但是当我尝试将其实现为我正在使用的代码时,它无法正常工作,它会在 Taphold 事件中发出警报,但不会在此处创建示例对话框代码我在用:
function createlist(){
alert("I am in create list");
db.transaction(function(tx){
tx.executeSql(select_nameUserDetails,[],function(tx,results){
$('#name').empty();
alert("from list "+results.rows.length);
if(results.rows.length>0)
{
for(var i=0;i<results.rows.length;i++)
{
alert(i);
$('#name').append('<li><p class="namelist" id="s'+i+'" onclick="selectname('+results.rows.item(i).id+')">'+results.rows.item(i).frist_name+'</p></li');
temp_id=results.rows.item(i).id;
dataobj[temp_id]=results.rows.item(i).frist_name;
alert(dataobj[temp_id]);
}
else{
alert("No data present");
}
});
$(document).on("taphold",".namelist",function(event){
alert("I am in taphold event");
event.stopPropagation();
$(this).simpledialog2({
mode:"blank",
headerText:"Image Options",
showModal:false,
forceInput:true,
headerClose:true,
blankContent:"<ul data-role='listview'><li><a href=''>Edit</a></li><li><a href=''>Delete</a></li></ul>"
});
});
});
}
这是使用的js和css文件:
<link rel="stylesheet" href="contactcss/jquery.mobile-1.3.1.min.css">
<link rel="stylesheet" href="css/jquery.mobile.simpledialog.min.css">
<script src="js/jquery.js"></script><script src="js/index.js"></script>
<script src="js/jquery.mobile-1.3.1.min.js"></script>
<script src="js/jquery.mobile.simpledialog2.min.js"></script>
<script type="text/javascript" charset="utf-8" src="js/cordova-2.7.0.js"></script>
这是html代码:
<div data-role="Content" >
<div data-role="listview" id="field">
<ul class="Name" id="name" data-role="listview" data-inset="true" data-theme="b">
</ul>
</div>
我得到的 logcat 错误:
07-13 17:29:33.145: D/CordovaLog(2696): TypeError: Result of expression 'o[0]' [undefined] is not an object.
07-13 17:29:33.145: E/Web Console(2696): TypeError: Result of expression 'o[0]' [undefined] is not an object. at file:///android_asset/www/js/jquery.mobile-1.3.1.min.js:4
提前致谢