Jquery 调用元素。单击()在ajax成功中失败
我在一个js文件中使用这个ajax调用,并在我使用的jsf页面中导入它 我在Chrome中调试这个部分,在$(“#close”)之前设置一个断点;然后我在控制台中键入这个,它会显示元素的html代码,但它不会单击该按钮,请帮助,我的代码有什么问题?多谢各位Jquery 调用元素。单击()在ajax成功中失败,jquery,ajax,jsf,mobile,Jquery,Ajax,Jsf,Mobile,我在一个js文件中使用这个ajax调用,并在我使用的jsf页面中导入它 我在Chrome中调试这个部分,在$(“#close”)之前设置一个断点;然后我在控制台中键入这个,它会显示元素的html代码,但它不会单击该按钮,请帮助,我的代码有什么问题?多谢各位 function doLogin(username, password) { $.ajax({ "type" : "post", "url" : "com.micros.hcp.mobile.ajax.common.AjaxM
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);
}
}
});
}
下面是我输入$(“close”)时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>
]
$(“#关闭”)。单击();
[
]
定义JS函数:
function clicked(){
alert('clicked');
}
将onclick
属性添加到
元素中
<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" onclick="clicked()">…</a>
你在锚定标签上有任何点击事件吗?我在代码中看不到任何内容…您需要定义它`$(“#关闭”)。单击(function(){alert('clicked');})`是的,我有,很抱歉没有贴在这里。我把这个放在盒子里form@XinshanBai:将其更改为
,但如果OP没有绑定到锚定标记的任何单击功能,它将触发什么?$('#关闭')。单击()
与$('#关闭')相同。触发('click')代码>谢谢你的想法,我以前尝试过触发器,但没有绑定部分,现在我按照你说的做了,但仍然不起作用…单击显示触发器何时执行,但对话框没有关闭。该按钮用于关闭对话框。很抱歉误解了问题,您必须将onClick
属性添加到
元素,查看更新的答案。我将其更改为,但如果我运行$(“#close”)。触发器('click');在控制台中,它仍然表示ReferenceError:clicked未定义,看起来它无法识别clicked()
$('#close').click();