创建不带display-javascript的alert()方法

creating the alert() method without the display - javascript

本文关键字:方法 alert display-javascript 创建      更新时间:2023-09-26

有没有一种方法可以复制alert()函数的功能,而不弹出??这可能看起来很疯狂,但这是有充分理由的。

编辑

这是我的代码:

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);

删除警报,它就会开始冻结。

我不知道这是否是你想要的,但我经常使用firebug和console.log调用来获取有关javascript正在做什么的信息,而不会干扰网站流。

但是,请记住,如果它是一个实时站点,请绕过console.log方法,因为任何没有firebug的人都会收到错误。

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

获取Firebug站点

阅读您的注释但不了解您的代码,这就是您想要实现的吗?

之前:

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

之后:

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

警报只有一个单独的用途,那就是显示一个弹出窗口,所以我想知道是什么原因…:)

但这是可能的,正如在SO.上所展示的那样

function alert(msg)
{
  // Ignore
}
window.alert = function(text) { }