创建不显示的alert()方法 - javascript

发布于 2024-11-14 09:46:38 字数 2001 浏览 2 评论 0原文

有没有一种方法可以复制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);

删除警报,它开始冻结。

is there a way that I can duplicate what the alert() function does, without the popup?? This might seem mad but there is good cause for this.

EDIT

Here is my code:

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

remove the alerts and it starts to freeze.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

恋竹姑娘 2024-11-21 09:46:38

我不知道这是否是您想要的,但我使用 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 站点

I don't know if this is what you are after but I use firebug and the console.log call a lot to get information about what the javascript is doing without interfering with the site flow.

remember however to bypass the console.log method if it is a live site as anyone without firebug will receive errors.

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

Get Firebug site

若相惜即相离 2024-11-21 09:46:38

阅读您的评论但不了解您的代码,这就是您想要实现的目标吗?

之前:

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

之后:

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

Reading your comments but not knowing your code, is this what you are trying to achieve?

before:

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

after:

function something() {
  a();
  b(); // needs a pause before executing c()
  setTimeout(c,10);
}
凉风有信 2024-11-21 09:46:38

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

但这是可能的,如此处所示所示。

function alert(msg)
{
  // Ignore
}

There is only one single use for alert, and that is showing a popup, so I wonder what that cause is. .. :)

But it is possible, as demonstrated here on SO.

function alert(msg)
{
  // Ignore
}
傲影 2024-11-21 09:46:38
window.alert = function(text) { }
window.alert = function(text) { }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文