English 中文(简体)
不从事聋人流动的时间安排
原标题:setTimeout not working on safari mobile

我有一项职能,即点击时显示一个菜单,我希望在5秒后消失。 这是我的 j脚印,在台式浏览器上运行得当,但在移动式浏览器上却消失。

$(function() {
    $( #prod_btn ).click(function() {
        $(this).addClass( selected ).next( ul ).css( display ,  block );
        setTimeout(hideMenu, 5000);
    });
});

function hideMenu() {
    $( #prod_btn ).removeClass( selected ).next( ul ).css( display ,  none );
}

问题在哪里?

增 编

问题回答

我刚才也存在同样的问题。 我的法典在我的Mac的任何浏览器上都非常适用,但是在iOs装置上,它不工作。

I use ".bind(this)" on my timeout function and that is what is causing the problem for me. When I extend the function object with ".bind" in my script it works like a charm.

我的法典就是这样:

searchTimeout = setTimeout(function() {
...
}.bind(this),250);

为此,我(如上所述)刚才补充说:

Function.prototype.bind = function(parent) {
    var f = this;
    var args = [];

    for (var a = 1; a < arguments.length; a++) {
        args[args.length] = arguments[a];
    }

    var temp = function() {
        return f.apply(parent, args);
    }

    return(temp);
}

我看不到你安排的时间,但对于有相同问题的其他人来说,可能是问题。 因此,我说:-

Keep in mind also that any setTimeout function is actually likely fire while DOM elements are rendering if the delay is set to a value too short. While that might seem obvious, it can be easily confused with no method firing whatsoever. A good way to test is to have an alert prompt run.

window.onLoad(alert("hey!"));

Then check to see if your function fires after.





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签