3
我对jQuery相当陌生,我在与代表团有关的问题上挣扎了一下。 在我的代码我有加载动态页面:jQuery Mobile .delegate()没有触发
$("#results").delegate('li', 'click', function(evt){
var queryData = "id=" + $(this).attr("id");
if ($(this).attr("id")){
$.ajax({
type: "GET",
url: "wiw_detail_page.html",
data: queryData,
beforeSend: onDetailBeforeSend,
success: onDetailSuccess,
error: onError
});
}
else
{
alert("Please select an Employee from the list");
}
return false;
});
这是onDetailSuccess功能:
function onDetailSuccess(data, status){
$("body").append(data);
$("#wiw_detail_page").page();
$.mobile.changePage("#wiw_detail_page", { transition: 'slide' });
}
一切运作良好,因为我得到我的第一个页面转移到“wiw_details_page”。 里面的新的一页我有字段列表,下一个可折叠的,这样的:
<div data-role="collapsible" data-collapsed="false" data-theme="b" id="comData">
<h2>Communication Data</h2>
<div id="communicationData">
<fieldset>
<label for="address">Address:</label>
<a href="#locationMap">
<input class="goMap" type="text"
name="address" id="address"
disabled="true"
value="<%=employeeprofile-building%>"/>
</a>
</fieldset>
</div>
</div>
我需要附加的地址输入栏点击处理程序,因为这个页面还没有在$创建(文件)。就绪()我连接了代表对这样的:
// Use delegation, since detail view is not availble at document.ready time:
$("#wiw_detail_page").delegate('input.goMap','click', function(evt){
if ($(this).attr("id") == 'address'){
alert("Click!");
if (navigator.geolocation) {
detectBrowser();
navigator.geolocation.getCurrentPosition(function(position){
newInitialize(position.coords.latitude, position.coords.longitude);
})
}else{
detectBrowser();
newInitialize(45.06150, 7.65599);
}
}
});
});
这个代表团从未发生,当我点击输入字段没有任何反应(甚至没有任何类型的错误)。
我也将选择更改为尝试:
$("#comData").delegate('input.goMap','click', function(evt)
而作为一个绝望的尝试,我改成了:
$("body").delegate('input.goMap','click', function(evt)
任何线索?
对不起,提前如此长的问题,谢谢, R.
您使用的是什么版本的jQuery和jQueryMobile的? – 2011-12-23 02:49:38
jquery-1.7.1.min.js和jquery.mobile-1.0.min.js – RobyPag 2011-12-23 02:55:37
jQM只支持jQuery版本1.6.4,我会建议降级并回发,在这里更多:http://jquerymobile.com/blog/2011/11/16 /宣布-jquery-mobile-1-0/ – 2011-12-23 02:59:33