[英]Revealed Close button in DIV not responsive on first click (or tap)
I have a problem where a revealed DIV does not close on the first attempt. 我有一个问题,在第一次尝试中显示的DIV无法关闭。 The user has to click at least once, anywhere on the page - doesn't have to be the close button, before they can click CLOSE to actually close the DIV.
用户必须至少单击一次页面上的任意位置-不必单击关闭按钮,然后才能单击“关闭”以实际关闭DIV。 First off though, there is a short lead up before the DIV.
首先,在DIV之前有一段短暂的领先时间。
I use a jquery mobile popup in my page to contain a single text field and submit button. 我在页面中使用jquery移动弹出窗口来包含单个文本字段和提交按钮。 It looks something like this (minus the layout).
看起来像这样(减去布局)。 The user submits their note through this popup.
用户通过此弹出窗口提交他们的笔记。
<div data-role="popup" id="popupBasic" data-corners="false">
<textarea rows="9" name="note" id="AttitionalNoteText"></textarea>
<a href="#" data-mini="true" id="submitnote" data-role="button">Submit</a>
<a href="#" data-rel="back" id="cancelSubmitNote" data-mini="true" data-role="button">Cancel</a>
</div>
When the user hits submit, I perform an ajax response to send the text to the server and upon success follow it up by revealing a hidden DIV as confirmation to the user. 当用户点击“提交”时,我执行ajax响应以将文本发送到服务器,并在成功后通过向用户显示隐藏的DIV作为确认来跟进。 I use a DIV instead of another popup since I realized that chaining popups is not possible within my ajax call.
我使用DIV而不是另一个弹出窗口,因为我意识到在ajax调用中不可能链接弹出窗口。
// this is called when the user hits submit in the popup
$("#submitnote").click(function (e) {
e.preventDefault();
// do stuff here to pass textstring
$("#popupBasic").hide();
$.ajax({
type: 'POST',
data: textstring,
url: '/something/addnote',
success: function (data) {
showConfirm(data); // upon success call the function below to open the DIV
}
});
$("#AttitionalNoteText").val("");
});
function showConfirm(data) {
document.getElementById("confirmMsg").innerHTML = data;
$("#confirmBox").show();
}
// this is to close that DIV
$("#closeConfirmBox").click(function (e) {
$("#confirmBox").hide();
});
Here's that simple DIV along with a close button. 这就是简单的DIV以及关闭按钮。
<div id="confirmBox">
<div id="confirmMsg" style="padding: 10px; font-size: 16px;">
this message gets replaced with whatever ajax call returned
</div>
<a href="#" id="closeConfirmBox" data-role="button">Close</a>
</div>
It seems that after the popup hides and my DIV comes up, the mouse does not show as a finger pointer until I've click somewhere on the page once. 似乎在弹出窗口隐藏并且我的DIV出现之后,直到我单击一次页面上的某个位置,鼠标才显示为手指指针。 Only then can I use the Close button on the DIV properly.
只有这样,我才能正确使用DIV上的“关闭”按钮。 The same happens on mobile, I have to tab somewhere on the screen before I can tap again on Close.
在移动设备上也会发生同样的情况,我必须在屏幕上的某个位置进行制表,然后才能再次单击“关闭”。 What can I do about this?
我该怎么办?
The problem is that you are not using the popup widget's close method , you are just hiding the div and leaving the modal screen in place. 问题是您没有使用弹出窗口小部件的close方法 ,只是隐藏了div并保留了模式屏幕。
Change; 更改;
$("#popupBasic").hide();
To: 至:
$("#popupBasic").popup( "close" );
BTW, if you do want to go with chained popups, have a look at this blog entry I wrote: http://jqmtricks.wordpress.com/2014/05/16/chained-popups-with-simpledialog2/ 顺便说一句,如果您确实想使用链式弹出窗口,请查看我写的此博客条目: http : //jqmtricks.wordpress.com/2014/05/16/chained-popups-with-simpledialog2/
$("#popupBasic").hide();
$("#popupBasic-screen").hide();
Added the above just before the ajax call. 在ajax调用之前添加了上述内容。
I think this wouldn't have been a problem if there was a proper solution to .popup("close") being undefined. 我认为,如果对.popup(“ close”)有一个未定义的正确解决方案,这将不是问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.