jQuery-对此jQuery代码进行故障排除 [英] jquery - troubleshooting this jquery code

查看:73
本文介绍了jQuery-对此jQuery代码进行故障排除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写此例程,用户可以单击3个按钮,然后将显示帮助div.

I am writing this routine where users can click on 3 buttons and the help divs will appear.

如果用户单击这三个按钮中的任何一个,则帮助div将切换并相应显示.用代码似乎可以正确完成此操作.

If the users click on any of the 3 buttons, the help divs will toggle and appear accordingly. This appears to be done correctly with the code.

如果用户单击帮助div中的关闭"按钮,则帮助div将消失.这似乎也正确地完成了.

If the users click on the "close" button inside the help div, the help div will disappear. This seems to be done correctly too.

如果用户在帮助窗口之外单击(但不在按钮上单击),则该窗口也将关闭.这似乎也可以.

If the users click outside of the help window (but not on the buttons), the window will also close. This seems to be OK too.

但是我遇到了一个障碍,如果用户单击帮助窗口中除关闭按钮之外的任何位置,希望帮助窗口保持打开状态.

But I am getting into a roadblock where I want the help window to stay open if the users click anywhere inside the help window except the close button.

我的代码在jsfiddle上,这里 http://jsfiddle.net/nzMAw/2/,我注释掉了jQuery行(接近尾声),这给了我这个问题.第一次运行脚本时,似乎无法正确执行.也就是说,如果我第一次按下任何按钮,都会弹出帮助窗口,但是如果我在窗口内单击,它将关闭.但是之后,当我再次按下按钮打开帮助窗口时,有问题的代码阻止了关闭"窗口的关闭.

My code is on jsfiddle here http://jsfiddle.net/nzMAw/2/, I commented out the jquery line (near the end) that is giving me the problem. It does not seem to get executed correctly when the script is run for the first time. That is if I press any button for the first time, the help window will popup, but it will close if I click inside the window. But after that, when I press the button again to open up the help window, the problematic code prevents the 'close' from closing the window.

我真的很感谢这里的任何见识.

I really appreciate any insight here.

TIA

$(function(){

$(document).click(function(event){

    var id = event.target.id;
    //var id=$(this).attr('id');
    //alert (id);
if (id == 'close')
{
    $(".aa").fadeOut("slow");
}
else if (id == '1' || id == '2' || id == '3' )
{    $(".aa").filter('#'+id+"div").fadeToggle("slow").end().not('#'+id+"div").fadeOut("slow").end();     //2 ends for not and filter destructive methods.   
}

else
{
    //$(".aa").click(function(){ return false; });//this statement is the problem

    $(".aa").fadeOut("slow");    
}
});
      });

推荐答案

$(".aa").click(function(e){ 
    e.preventDefault();
});

也在这里:

http://jsfiddle.net/p6c93/

这篇关于jQuery-对此jQuery代码进行故障排除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆