2011-06-09 117 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); 
}