jquerymobile';s listview li项单击未激发
我在jquery mobile的listview中遇到问题 listview动态生成。onclick li项事件未触发,未发生错误 Jquery函数jquerymobile';s listview li项单击未激发,jquery,ajax,html,jquery-mobile,Jquery,Ajax,Html,Jquery Mobile,我在jquery mobile的listview中遇到问题 listview动态生成。onclick li项事件未触发,未发生错误 Jquery函数 function GetDependents() { var userid= checkCookie1(); "use strict"; var wcfServiceUrl = "http://xcxcxcx/PHRService/Service1.svc/XMLService/"; $.ajax({
function GetDependents() {
var userid= checkCookie1();
"use strict";
var wcfServiceUrl = "http://xcxcxcx/PHRService/Service1.svc/XMLService/";
$.ajax({
url: wcfServiceUrl + "Dependents",
data: "PatientID=" + userid + "",
type: "GET",
processData: false,
contentType: "application/json",
timeout: 10000,
dataType: "json",
cache:false,
beforeSend: function (xhr) {
$.mobile.showPageLoadingMsg();
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
},
complete: function () {
$.mobile.hidePageLoadingMsg();
},
success: function (data) {
var result = data.GetDependentsResult;
var items = [];
$.each(result, function (i, item) {
items.push('<li><a onclick=redirect(\'AddDependents.htm?id=' + item.ItemID + '\');\>' + item.ItemName + '</a></li>');
});
$('#main_list').append(items.join(''));
$('#main_list').listview('refresh');
},
error: function (data) {
}
});
}
函数GetDependents(){
var userid=checkCookie1();
“严格使用”;
var wcfServiceUrl=”http://xcxcxcx/PHRService/Service1.svc/XMLService/";
$.ajax({
url:wcfServiceUrl+“依赖项”,
数据:“PatientID=“+userid+”,
键入:“获取”,
processData:false,
contentType:“应用程序/json”,
超时:10000,
数据类型:“json”,
cache:false,
发送前:函数(xhr){
$.mobile.showPageLoadingMsg();
setRequestHeader(“内容类型”,“应用程序/x-www-form-urlencoded”);
},
完成:函数(){
$.mobile.hidePageLoadingMsg();
},
成功:功能(数据){
var result=data.GetDependentsResult;
var项目=[];
$。每个(结果、功能(i、项目){
items.push(“”+item.ItemName+” );
});
$(“#主列表”).append(items.join(“”));
$('主列表').listview('刷新');
},
错误:函数(数据){
}
});
}
HTML是
<div data-role="content" data-theme="c">
<ul data-role="listview" id="main_list">
</ul>
<br />
<a onclick="redirect('AddDependents.htm');" data-role="button" data-icon="plus">Add new...</a>
</div>
添加新的。。。
请帮助我解决此问题。调用事件比使用内联javascript要好 试试这个 HTML
items.push('<li><a id="'+ item.ItemID + '">' + item.ItemName + '</a></li>');
由于您是在上动态添加元素,因此应使用委派事件
注意:我可以看到
标签有一个额外的结束符
<a onclick=redirect(\'AddDependents.htm?id=' + item.ItemID + '\');\>'
//---^^---here
'
//---^^---这里
您有一个额外的
\
is closing标记
调用事件比使用内联javascript要好
试试这个
HTML
items.push('<li><a id="'+ item.ItemID + '">' + item.ItemName + '</a></li>');
由于您是在上动态添加元素,因此应使用委派事件
注意:我可以看到
标签有一个额外的结束符
<a onclick=redirect(\'AddDependents.htm?id=' + item.ItemID + '\');\>'
//---^^---here
'
//---^^---这里
您有一个额外的
\
正在关闭标记
,无效的html几乎肯定是它不启动的原因。内联更难看,更难管理,但它不应该阻止它工作(除非jqm将其附加到其他元素),但无效的html肯定会阻止它工作。好眼力。无效的html几乎肯定是它不启动的原因。内联更难看,更难管理,但它不应该阻止它工作(除非jqm将其附加到其他元素),但无效的html肯定会阻止它工作。好眼力。