문제

I would like to show only "#HideLgf" when "#LGF_info" is clicked/checked otherwise hide it, how is it possible ?

        $(document).ready(function(){
        $('#LGF_info').click(function() {
            $('#HideLgf').show(100);
        });

        $('#DDP_info').click(function () {
            $('#HideLgf').hide();
        });

        $('#EXW_info').click(function () {
            $('#HideLgf').hide();
        });


        $('#DDU_info').click(function () {
            $('#HideLgf').hide();
        });


    });
도움이 되었습니까?

해결책

Easy. But I must admit that I'd probably change a lot more (e.g. use a class instead of show()/hide(), less IDs, a proper function, etc.), but as that's all you've provided us with. And using event delegation via on removes the often required domReady call and allows to reuse the callbacks on e.g. dynamically added content.

$(document)
    .on("click", "#DDP_info, #EXW_info, #DDU_info", function(e) {
        $("#HideLgf").hide();
    })
    .on("click", "#LGF_info", function(e) {
        $("#HideLgf").show(100);
    })
;

다른 팁

Try using a multiple selector here to simplify your code,

$('#LGF_info,#DDP_info,#EXW_info,#DDU_info').click(function () {           
   var cache = $('#HideLgf');
   if(this.id == "HideLgf") {
    cache.stop().show(100);
   }
   else {
    cache.hide();
   } 
});
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top