创建不显示的alert()方法 - javascript
有没有一种方法可以复制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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我不知道这是否是您想要的,但我使用 firebug 和 console.log 多次调用来获取有关 javascript 正在执行的操作的信息,而不会干扰站点流程。
但请记住,如果它是一个实时站点,请绕过 console.log 方法,因为任何没有 firebug 的人都会收到错误。
获取 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.
Get Firebug site
阅读您的评论但不了解您的代码,这就是您想要实现的目标吗?
之前:
之后:
Reading your comments but not knowing your code, is this what you are trying to achieve?
before:
after:
警报只有一种用途,那就是显示弹出窗口,所以我想知道原因是什么。 .. :)
但这是可能的,如此处所示所示。
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.