2011-06-09 119 views
1

有没有一种方法,我可以复制alert()函数做什么,没有弹出?这看起来可能很疯狂,但有一个很好的原因。创建alert()方法没有显示 - javascript

EDIT

这是我的代码:

var navActive; 
var pageID; 
var maxNav; 
var popWidth = $(window).width(); 
var popHeight = $(window).height(); 

function thread_start(callback) { 

    setTimeout(callback, 1); 
    return true; 
} 

(function($){ 

$.fn.foneySlide = function (options) { 

    $(window).resize(function(){ 
     popWidth = $(window).width() - 40; 
     popHeight = $(window).height() - 40; 
    }) 

    opt = $.extend ({ popOnTransition : true }, options); 

    // firstly give all navigation items a position reference for continous slide 
    $('[data-role=page]').each(function(i){ 
     $(this).attr('navpos', i); 
     if(typeof $('[data-role=page]')[i+1] == 'undefined') { 
      maxNav = i; 
     } 
    }); 

    // get the current active page and the default navigation position 
    pageID = $('.ui-page-active').attr('id'); 
    navActive = $('#' + pageID).attr('navpos'); 

    // change page on swipe left  
    $('body').bind('swipeleft', function(e){ 
     if(navActive == maxNav) { 
      navActive = 0; 
      alert(); 
      thread_start("$.mobile.changePage($('[navpos=0]'), 'slide', false, true)"); 
     }else{ 
      navActive = Number(navActive + 1); 
      alert(); 
      thread_start("$.mobile.changePage($('[navpos=' + navActive + ']'), 'slide', false, true)"); 
     } 
    }); 

    // change page on swipe right     
    $('body').bind('swiperight', function(e){ 
     if(navActive == 0) { 
      navActive = maxNav; 
      alert(); 
      thread_start("$.mobile.changePage($('[navpos=' + navActive + ']'), 'slide', true, true)"); 
     }else{ 
      navActive = Number(navActive - 1); 
      alert(); 
      thread_start("$.mobile.changePage($('[navpos=' + navActive + ']'), 'slide', true, true)"); 
     } 
    }); 
} 

})(jQuery的);

删除警报并开始冻结。

+1

没有弹出什么是警报? – ErikPerik 2011-06-09 11:29:47

+3

警报功能做什么,没有弹出? – Gareth 2011-06-09 11:29:55

+0

假设所有警报都会显示一个弹出窗口,我想知道如果不想弹出窗口,预期的结果是什么。这就像是远离夏日假期的阳光。你留下来,没有:-) – 2011-06-09 11:31:14

回答

0

只有一个用于警报,这是显示一个弹出窗口,所以我想知道是什么原因。 .. :)

但它是可能的,如演示here on SO

function alert(msg) 
{ 
    // Ignore 
} 
+0

不能得到这个工作,不断抛出错误 – 2011-06-09 11:42:35

+0

我认为它就像我刚刚添加的示例一样简单。 javascript中的全局上下文实际上是在窗口对象内部,因此重新声明alert函数将覆盖它。 – GolezTrol 2011-06-09 12:49:07

+0

但是,如果您发现特定的错误,那么发布代码和发生的错误会很有帮助。 – GolezTrol 2011-06-09 12:49:39

-1
window.alert = function(text) { } 
0

我不知道这是否是你所追求的,但我使用Firebug和执行console.log调用了很多,以获取有关什么JavaScript是不与网站流量干扰情况的信息。

但是请记住,如果它是一个活网站,那么不要绕过console.log方法,因为没有萤火虫的人将会收到错误。

if(typeof console == 'undefined') { 
    console = function(){} 
    console.log = function(txt){} 
    console.warn = function(txt){} 
} else console.log('Console Active'); 

Get Firebug site

0

读你的意见,但不知道你的代码,这是你要实现的目标是什么?

前:

function something() { 
    a(); 
    b(); // needs a pause before executing c() 
    c(); 
} 

后:

function something() { 
    a(); 
    b(); // needs a pause before executing c() 
    setTimeout(c,10); 
}