点击文档jQuery时隐藏的元素

时间:2014-11-01 11:06:30

标签: jquery click toggle

JS Fiddle

如果textarea为空且用户点击textarea之外,我会隐藏按钮。 但是当textarea为空并且用户点击按钮下方的任何按钮时,隐藏但是运行各自的功能。 谁能帮我 ?

3 个答案:

答案 0 :(得分:0)

我不完全理解你的问题,但我理解的是你正在寻找event.stopPropagation();。像这样使用:

//apply a click event on the button
$('button').on('click',function(e){
//stop other event from firing when click on this
          e.stopPropagation();
//do you stuff with the button.....
});

这会阻止其他事件在你点击时触发,除了它自己的事件!

答案 1 :(得分:0)

blur的{​​{1}}事件中,添加了一个检查按钮的父div(textarea)是否悬停的情况,如果是,则不要隐藏它。< / p>

更新了Javascript:

.tog

<强> Fiddle

答案 2 :(得分:0)

Please Try This.
<script>
    var  c ;
 $('textarea').focus(function () {
    c = $(this).closest('.c');
    var a = $('#mytextid').val();
    if (a == '') {

    }
    else{
         c.children('.tog').show();
    }

}).keyup(function () {
    if(!$(this).val().length > 0){
    c = $(this).closest('.c');
    c.children('.tog').hide();
    }
    else
    {
        c.children('.tog').show();   
    }
});
$('.upload').click(function () {
alert('choose a file to upload');
});
$('.clear').click(function () {
alert('cleared');
});
$('.save').click(function () {
alert('saved');
});   

</script>

if this answer is complete your condition  so  please like.Thanks 
相关问题