Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 单击“其他”按钮时如何使div自动隐藏_Javascript_Jquery_Html_Css_Cakephp 2.0 - Fatal编程技术网

Javascript 单击“其他”按钮时如何使div自动隐藏

Javascript 单击“其他”按钮时如何使div自动隐藏,javascript,jquery,html,css,cakephp-2.0,Javascript,Jquery,Html,Css,Cakephp 2.0,我正在使用带div的show/hide滑块。我的编码工作正常。。 但我希望我的div或我的内容在我单击另一个按钮(编码中的图像)时自动隐藏) 我希望任何人都能帮我做这件事提前谢谢 这是我的html <div id="slidingDiv"> <a href="#" class="show_hide" rel="#slidingDiv11"> <img src="../img/choose/mens.png"> </a>

我正在使用带div的show/hide滑块。我的编码工作正常。。 但我希望我的div或我的内容在我单击另一个按钮(编码中的图像)时自动隐藏)

我希望任何人都能帮我做这件事提前谢谢

这是我的html

<div id="slidingDiv">
    <a href="#" class="show_hide" rel="#slidingDiv11">
        <img src="../img/choose/mens.png">
    </a>

    <a href="#" class="show_hide" rel="#slidingDiv12">
        <img src="../img/choose/womens.png">
    </a>
    <div id="slidingDiv11">
        <img src="../img/choose/clothings.png"><br><br>
        <img src="../img/choose/shoes.png"><br><br>
        <img src="../img/choose/bags.png"><br><br>
        <img src="../img/choose/accessories.png">
    </div>
    <div id="slidingDiv12">
        <img src="../img/choose/clothings.png"><br><br>
        <img src="../img/choose/shoes.png"><br><br>
        <img src="../img/choose/bags.png"><br><br>
        <img src="../img/choose/accessories.png">
    </div>
</div>
<div id="slidingDiv1">
    <a href="#" class="show_hide" rel="#slidingDiv16">
        <img src="../img/choose/book.png">
    <a>
    <a href="#" class="show_hide" rel="#slidingDiv17">
        <img src="../img/choose/textbooks.png">
    </a>

    <div id="slidingDiv16">
        <img src="../img/choose/books1.png">
        <img src="../img/choose/books1.png">
        <img src="../img/choose/books1.png">
    </div>
    <div id="slidingDiv17">
        <img src="../img/choose/textbooks1.png">
        <img src="../img/choose/textbooks1.png">
        <img src="../img/choose/textbooks1.png">
    </div>
</div>
这是我的js

$(document).ready(function () {
    $('.show_hide').showHide({
        speed: 1000, // speed you want the toggle to happen 
        easing: '', // the animation effect you want. Remove this line if you dont want an effect and if you haven't included jQuery UI
        changeText: 0, // if you dont want the button text to change, set this to 0
        showText: 'View', // the button text to show when a div is closed
        hideText: 'Close' // the button text to show when a div is open
    });
});

(function ($) {
    $.fn.showHide = function (options) {

        //default vars for the plugin
        var defaults = {
            speed: 1000,
            easing: '',
            changeText: 0,
            showText: 'Show',
            hideText: 'Hide'

        };
        var options = $.extend(defaults, options);

        $(this).click(function () {

            $('.toggleDiv').slideUp(options.speed, options.easing);
            // this var stores which button you've clicked
            var toggleClick = $(this);
            // this reads the rel attribute of the button to determine which div id to toggle
            var toggleDiv = $(this).attr('rel');
            // here we toggle show/hide the correct div at the right speed and using which easing effect
            $(toggleDiv).slideToggle(options.speed, options.easing, function () {
                // this only fires once the animation is completed
                if (options.changeText == 1) {
                    $(toggleDiv).is(":visible") ? toggleClick.text(options.hideText) : toggleClick.text(options.showText);
                }
            });

            return false;
        });
    };
})(jQuery);
使用jQuery

$("your_other_button").on('click', function() {
      $("your_div_to_hide").hide();
});
使用jQuery

$("your_other_button").on('click', function() {
      $("your_div_to_hide").hide();
});
使用jQuery

$("your_other_button").on('click', function() {
      $("your_div_to_hide").hide();
});
使用jQuery

$("your_other_button").on('click', function() {
      $("your_div_to_hide").hide();
});
使用Jquery

$("other_button").on('click', function() {
    $("div_to_hide").toggle();
});
使用Jquery

$("other_button").on('click', function() {
    $("div_to_hide").toggle();
});
使用Jquery

$("other_button").on('click', function() {
    $("div_to_hide").toggle();
});
使用Jquery

$("other_button").on('click', function() {
    $("div_to_hide").toggle();
});

由于要在单击按钮时隐藏
div
,因此在单击隐藏时应将其设置为
文档。试试这样的

$(“.hide_show”)。单击(函数(事件){event.stopPropagation();$(this.fadeToggle(1000);})$(文档)。单击(函数(){$(“.hide_show).fadeOut(1000);});


使用
event.stopPropagation();
停止文档事件以触发
.hide\u show
类。这可能会对您有所帮助。

由于您希望在单击按钮时隐藏
div
,因此在单击隐藏时应将其设置为
文档。尝试类似的操作

$(“.hide_-show”)。单击(函数(事件){event.stopPropagation();$(此).fadeToggle(1000);$(文档)。单击(函数(){$(“.hide_-show).fadeOut(1000);})


使用
event.stopPropagation()
停止触发
的文档事件。hide\u show
类。这可能会对您有所帮助。

由于您希望在单击按钮时隐藏
div
,因此在单击隐藏时应将其设置为
文档。试试这样的

$(“.hide_show”)。单击(函数(事件){event.stopPropagation();$(this.fadeToggle(1000);})$(文档)。单击(函数(){$(“.hide_show).fadeOut(1000);});


使用
event.stopPropagation();
停止文档事件以触发
.hide\u show
类。这可能会对您有所帮助。

由于您希望在单击按钮时隐藏
div
,因此在单击隐藏时应将其设置为
文档。尝试类似的操作

$(“.hide_-show”)。单击(函数(事件){event.stopPropagation();$(此).fadeToggle(1000);$(文档)。单击(函数(){$(“.hide_-show).fadeOut(1000);})




使用
event.stopPropagation()
停止触发
的文档事件。hide\u show
类。这可能会对您有所帮助。

请注意正确设置代码格式。它使你和其他人更容易阅读。你能做小提琴吗?它会有帮助的coding@TusharGupta已编辑请注意正确格式化代码。它使你和其他人更容易阅读。你能做小提琴吗?它会有帮助的coding@TusharGupta已编辑请注意正确格式化代码。它使你和其他人更容易阅读。你能做小提琴吗?它会有帮助的coding@TusharGupta已编辑请注意正确格式化代码。它使你和其他人更容易阅读。你能做小提琴吗?它会有帮助的coding@Tushar古普塔已经编辑好了我可以在哪里写这个?我可以在哪里写这个?我可以在哪里写这个?我可以在哪里写这个?谢谢..对不起,我是编程新手..我应该把它放在哪里??以及如何使用event.stopPropagation();很抱歉好的,如果您有两个类为
div
。单击_toggle
toggle\u div
,您想隐藏和显示
。当您单击
单击_toggle
时,切换_div
。您应该像这样应用
jquery
(“.click\u toggle”)。单击(function(){$(“.toggle\u div”).toggle();})
现在,当您在其外部单击时,您希望隐藏
toggle_dive
,您应该应用另一个类似于
$(文档)的代码。单击(function(){$(“.toggle_div”).hide()
如果您甚至不想让文档触发
。单击“切换”
事件,您应该将其设置为“$”(“.click\u toggle”)。单击(函数(e)(e.stopPropagation();而不是
$(“.click\u toggle”)。单击(函数(){$(“.toggle\u div”).toggle();
,因为如果不添加
e.stopPropagation(),可能会导致Js出现故障
。注意。
事件
e
相同。谢谢你的帮助。它可以工作。但是当我在它外面单击时,我的div没有隐藏,而是它被禁用或消失了。我只想在单击其他按钮时我的div向上滑动。谢谢。对不起,我是编程新手。我应该放在哪里?以及如何使用event.stopPropagation();抱歉。好的,如果您有两个类为
div
。单击
切换
,您想隐藏和显示
。当您单击
单击
时,切换
。您应该像这样应用
jquery
($)。单击
。切换”)。单击(函数(){(“。切换
)。切换()
现在,当您在其外部单击时,您想隐藏
切换
,您应该应用另一个类似
$(文档)的代码。单击(function(){$(“.toggle\u div”).hide();
如果您甚至不想让文档触发
。单击切换
事件,您应该将其设置为`$(“。单击切换”)。单击(function(e)(e.stopPropagation();而不是
$(“.click_toggle”)。单击(function(){$(“.toggle_div”).toggle();})
,因为如果不添加
e.stopPropagation(),可能会导致Js出现故障
。注意。
事件
e
相同。谢谢你的帮助。它可以工作。但是当我在它外面单击时,我的div没有隐藏,而是它被禁用或消失了。我只想在单击其他按钮时我的div向上滑动。谢谢。对不起,我是编程新手。我应该把它放在哪里?