简体   繁体   English

jQuery移动块执行或退出

[英]jquery mobile block execution or exit

There are some very interesting questions here for stopping execution and most of these relate to pausing for a certain time before something else is allowed to occur. 这里有一些非常有趣的问题可用于停止执行,其中大多数与在允许发生其他事情之前暂停一定时间有关。

I have a slightly different scenario in my jquery mobile 1.3.2 with the following function which adds an event to user's calendar. 我在jquery mobile 1.3.2中有一个稍微不同的方案,它具有以下功能,该功能将事件添加到用户的日历中。

    function addToMyCal(typ,id)
    {
        loginReq();
        addToUsrCal(window.wh2usr,"spscId",id);
    }
    // login required
    function loginReq()
    {
         // check cookie
        if (! loginCheck())
            $('#popupLogin').popup('open')
    }

I observe that, if a user is not logged in, then the login popup is shown but it does not pause to get user credentials. 我观察到,如果用户未登录,则会显示登录弹出窗口,但不会暂停以获取用户凭据。 Instead the login popup is displayed, addToUsrCal() is called right away, which fails because there is no user information. 而是显示登录弹出窗口,而是立即调用addToUsrCal(),该操作失败,因为没有用户信息。

So how do I 1) either wait till user provides credentials without a timeout or 2) allow user to cancel the login and return back to where they were on the site? 因此,我该如何1)等待用户提供凭据而没有超时,或者2)允许用户取消登录并返回到他们在网站上的位置?

Thanks 谢谢

Your call to $('#popupLogin').popup doesn't wait for any user interaction - it just displays the popup and immediately returns. 您对$('#popupLogin').popup调用不会等待任何用户交互-它仅显示弹出窗口并立即返回。 Then the loginReq function is finished and returns to the caller, addToMyCal . 然后loginReq函数完成,并返回到调用方addToMyCal From there, the next line in addToMyCal is executed - the call to addToUsrCal . 从那里开始,执行addToMyCal的下一行-对addToUsrCal的调用。

If you want to call addToUsrCal only after some user input, then you'll need to move that function call to a callback function - probably tied to the submit action on a form or the click action of a submit button (these presumably already exist in your popup's content). 如果您只想在某些用户输入后调用addToUsrCal ,则需要将该函数调用移至回调函数-可能与表单上的addToUsrCal按钮的click操作相关(这些可能已经存在于其中)您的弹出式窗口的内容)。

Similarly, you can add a callback to a cancel button in the popup that will close the popup (using a call to $('#popupLogin').popup("close") . 同样,您可以在弹出窗口的“取消”按钮中添加一个回调,以关闭弹出窗口(使用对$('#popupLogin').popup("close")的调用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM