Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/453.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 Onclick,只有父div而不是subdiv_Javascript_Jquery_Html_Css_Modal Dialog - Fatal编程技术网

Javascript Onclick,只有父div而不是subdiv

Javascript Onclick,只有父div而不是subdiv,javascript,jquery,html,css,modal-dialog,Javascript,Jquery,Html,Css,Modal Dialog,我正在构建一个基本的模态窗口,我希望它在单击边缘时消失。所以我的问题是最基本的形式: <div style="width:100%;height:100%;" onclick="hideAll()"> Hide all onclick. <div style="width:100px;height:100px;"> does not hide all onclick </div> </div> 隐藏所有o

我正在构建一个基本的模态窗口,我希望它在单击边缘时消失。所以我的问题是最基本的形式:

<div style="width:100%;height:100%;" onclick="hideAll()">
    Hide all onclick.
    <div style="width:100px;height:100px;">
        does not hide all onclick
    </div>
</div>

隐藏所有onclick。
不隐藏所有onclick
实现这一目标的最佳方式是什么?使用未列出的div?html/css魔术?

请看这把小提琴:

看这把小提琴:


您可以使用基本jQuery并使用CSS对其进行相应的样式设置。 检查

如果要通过在对话框窗口外单击使其消失,请确保单击后执行此操作:

$( "#dialog_id" ).dialog( "close" );

您可以使用基本jQuery并使用CSS对其进行相应的样式设置。 检查

如果要通过在对话框窗口外单击使其消失,请确保单击后执行此操作:

$( "#dialog_id" ).dialog( "close" );

当您隐藏父标记时,它也会自动隐藏childen标记,您应该首先将childdiv包含到变量中,然后隐藏父div并将存储的childdiv附加到父标记中,类似这样的内容

HTML

<div id="result">
    <div style="width:100%;height:100%;" id="parentDiv" onclick="hideAll()">
        Hide all onclick.
        <div style="width:100px;height:100px;" id="childDiv">
            does not hide all onclick
        </div>
    </div>
</div>

当您隐藏父标记时,它也会自动隐藏子标记,您应该首先将子div包含到变量中,然后隐藏父div,并将存储的子div附加到父标记中,类似这样的内容

HTML

<div id="result">
    <div style="width:100%;height:100%;" id="parentDiv" onclick="hideAll()">
        Hide all onclick.
        <div style="width:100px;height:100px;" id="childDiv">
            does not hide all onclick
        </div>
    </div>
</div>
HTML:

<div style="width:100%;height:100%;" class="outerModal">
    Hide all onclick.
    <div style="width:100px;height:100px;">
        does not hide all onclick
    </div>
</div>
$(document).on("click", ".outerModal", function(evt) {  //listen for clicks
    var target = $(evt.target ||evt.srcElement);  //get the element that was clicked on
    if (target.is(".outerModal")) {  //make sure it was not a child that was clicked. 
        //hide dialog
    }
});
示例:

<div style="width:100%;height:100%;" class="outerModal">
    Hide all onclick.
    <div style="width:100px;height:100px;">
        does not hide all onclick
    </div>
</div>
$(document).on("click", ".outerModal", function(evt) {  //listen for clicks
    var target = $(evt.target ||evt.srcElement);  //get the element that was clicked on
    if (target.is(".outerModal")) {  //make sure it was not a child that was clicked. 
        //hide dialog
    }
});
HTML:

<div style="width:100%;height:100%;" class="outerModal">
    Hide all onclick.
    <div style="width:100px;height:100px;">
        does not hide all onclick
    </div>
</div>
$(document).on("click", ".outerModal", function(evt) {  //listen for clicks
    var target = $(evt.target ||evt.srcElement);  //get the element that was clicked on
    if (target.is(".outerModal")) {  //make sure it was not a child that was clicked. 
        //hide dialog
    }
});
示例:

<div style="width:100%;height:100%;" class="outerModal">
    Hide all onclick.
    <div style="width:100px;height:100px;">
        does not hide all onclick
    </div>
</div>
$(document).on("click", ".outerModal", function(evt) {  //listen for clicks
    var target = $(evt.target ||evt.srcElement);  //get the element that was clicked on
    if (target.is(".outerModal")) {  //make sure it was not a child that was clicked. 
        //hide dialog
    }
});

假设“parentDiv”是背景,“childDiv”是实际的模态内容,我发现最好的方法是将div完全分开

HTML

CSS

希望这能有所帮助。

假设“parentDiv”是背景,而“childDiv”是实际的模态内容,我发现最好的方法是将div完全分开

HTML

CSS


希望这能有所帮助。

hideAll()
为什么你没有发布这个js函数?并且应该使用最具攻击性的javascript和最受欢迎的方式。html/css魔术?你这是什么意思?
hideAll()
为什么你没有发布这个js函数?并且应该使用最具攻击性的javascript和最受欢迎的方式。html/css魔术?你这是什么意思?顺便说一句,我把身份证加在了部门的名单上了。。父对象将隐藏所有,子对象将不。。。。等等,你是说你只想隐藏父母而不是孩子????如果是的话,那是另一个问题。顺便说一句,我把身份证添加到了部门。是的。。父对象将隐藏所有,子对象将不。。。。等等,你是说你只想隐藏父母而不是孩子????如果是的话,那是另一个问题。