我在單個js文件中使用此ajax調用,並將其導入到我正在使用的jsf頁面中。我在Chrome中調試了這個部分,我在$(「#close」)之前設置了一個斷點。然後我在控制檯中鍵入它,它出來的元素的HTML代碼,但它不會單擊該按鈕,請幫助,我的代碼有什麼問題?謝謝。在ajax成功時調用element.click()失敗
function doLogin(username, password) {
$.ajax({
"type" : "post",
"url" : "com.micros.hcp.mobile.ajax.common.AjaxMSMLoginDialog.ajax",
data : {
"username" : username,
"password" : password
},
dataType : "text",
async: false,
error : function(msg) {
alert(msg);
$.mobile.hidePageLoadingMsg();
notification("Login failed.");
},
success : function(data) {
data = String(data).trim();
if (data == "login_success") {
alert($("#close").attr("id")); // make sure I can get the element
$("#close").click();
} else {
addErrorMessage(data);
}
}
});
}
以下
的結果在Chrome控制檯顯示當我輸入$(「親密」)點擊()。在斷點處。在Ajax調用之後,如果我在控制檯中運行它,它將起作用。
$("#close").click();
[
<a href="#" id="close" data-role="button" data-rel="back" style="display: none; " data- corners="true" data-shadow="true" data-iconshadow="true" data-wrapperels="span" data-theme="c" class="ui-btn ui-btn-up-c ui-shadow ui-btn-corner-all" data-transition="slideup" data- direction="reverse">…</a>
]
你做錨標籤上有任何點擊事件?沒有可見的,我可以看到你的代碼... – Chris 2012-07-20 13:06:06
你需要定義它'$(「#close」)。click(function(){alert('clicked');});' – 2012-07-20 13:08:32
是的,抱歉沒有粘貼在這裏。我有這個表單內 – 2012-07-20 13:08:57