关闭/隐藏模态

时间:2017-01-20 11:48:55

标签: javascript jquery html css

我很难在填满后关闭或隐藏我的模态。

点击提交后,我希望它返回文本框可点击的页面。回到页面后,当我再次打开它时,我检查的复选框仍应检查。任何人都可以使用javascript或任何其他解决方案。

我现在没有时间使用bootstrap,我的代码在下面。我只想隐藏我的模态或点击提交时关闭。请帮帮我,谢谢。

我的工作小提琴:https://jsfiddle.net/fe73awsu/

请参阅下面的代码:

test.php的

<form method="post" name="testform" action="#">

    <a href="#modal"> <!-- when the input textbox was clicked, modal will pop up -->
        <input readonly type="text" name="txt1" placeholder="inputTest">        
    </a>

    <div class="modalwrapper" id="modal">   <!-- modal -->
            <div class="modalcontainer">    
                <div class="modalcol1">
                    <label>Test 1</label>
                    <input type="checkbox" name="test_modal[]" value="1">
                    <div class="clear"></div>
                    <label>Test 2</label>
                    <input type="checkbox" name="test_modal[]" value="2">
                    <div class="clear"></div>
                    <label>Test 3</label>
                    <input type="checkbox" name="test_modal[]" value="3">
                    <div class="clear"></div>
                    <label>Test 4</label>
                    <input type="checkbox" name="test_modal[]" value="4">
                    <div class="clear"></div>
                    <label>Test 5</label>
                    <input type="checkbox" name="test_modal[]" value="5">
                    <div class="clear"></div>

                    <div class="savebutton">
                        <button class="btn1" type="button" value="Submit">Submit</button>
                    </div>
                </div> <!-- close modalcol1 -->
            </div> <!-- close modalcontainer -->
        <div class="overlay"></div>
    </div> <!-- close modalwrapper -->
</form>

modal.css

/* modal layout */
    .modalwrapper {
        top: 0;
        left: 0;
        opacity: 0;
        position: absolute;
        visibility: hidden;
        box-shadow: 0 3px 7px rgba(0,0,0,.25);
        box-sizing: border-box;
        transition: all .4s ease-in-out;
        -webkit-transition: all .4s ease-in-out;
        -moz-transition: all .4s ease-in-out;
    }

    .modalwrapper:target {
        opacity: 1;
        visibility: visible
    }

    .overlay {
        background-color: #000;
        background: rgba(0,0,0,.8);
        height: 100%;
        left: 0;
        position: fixed;
        top: 0;
        width: 100%;
        z-index: 1;
    }

    .modalcontainer {
        display: table;
        background-color: #777;
        position: relative;
        z-index: 100;
        color: #fff;
        padding: 5px;
    }

    .modalcol1 { display: table-cell; }

    .clear { clear: both; }

    .modalwrapper input[type=checkbox] {
        float: right;
        margin-right: 20px;
    }

    .savebutton input[type=submit] {
        float: right;
        background-color: maroon;
        color: #fff;
        border: none;
        padding: 5px 10px;
        margin-top: 5px;
        margin-right: 20px;
    }
    /* modal layout ends here */

请帮帮我们:(我现在非常需要它。

5 个答案:

答案 0 :(得分:1)

冷静下来,

检查此jsfiddle链接。

添加此js代码,

   $(document).on("click",".btn1", function(){
   $('#modal').hide();
   });

为什么这么认真?

答案 1 :(得分:1)

<button type="button" id="close"class="btn green btn-default" data-dismiss="modal">Close <i class="fa fa-times" aria-hidden="true"></i></button>

添加JavaScript

function onSave(){
$('#close').Click();
}

答案 2 :(得分:0)

试试这个。

<button class="btn1" type="button" value="Submit" on-click= submit();>Submit</button>

//脚本

function submit() {
   window.history.back();
}

答案 3 :(得分:0)

&#13;
&#13;
   $(document).on("click",".btn1", function(){
   $('#modal').hide();
   });
&#13;
/* modal layout */
    .modalwrapper {
        top: 0;
        left: 0;
        opacity: 0;
        position: absolute;
        visibility: hidden;
        box-shadow: 0 3px 7px rgba(0,0,0,.25);
        box-sizing: border-box;
        transition: all .4s ease-in-out;
        -webkit-transition: all .4s ease-in-out;
        -moz-transition: all .4s ease-in-out;
    }

    .modalwrapper:target {
        opacity: 1;
        visibility: visible
    }

    .overlay {
        background-color: #000;
        background: rgba(0,0,0,.8);
        height: 100%;
        left: 0;
        position: fixed;
        top: 0;
        width: 100%;
        z-index: 1;
    }

    .modalcontainer {
        display: table;
        background-color: #777;
        position: relative;
        z-index: 100;
        color: #fff;
        padding: 5px;
    }

    .modalcol1 { display: table-cell; }

    .clear { clear: both; }

    .modalwrapper input[type=checkbox] {
        float: right;
        margin-right: 20px;
    }

    .savebutton input[type=submit] {
        float: right;
        background-color: maroon;
        color: #fff;
        border: none;
        padding: 5px 10px;
        margin-top: 5px;
        margin-right: 20px;
    }
    /* modal layout ends here */
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form method="post" name="testform" action="">

	<a href="#modal"> <!-- when the input textbox was clicked, modal will pop up -->
		<input readonly type="text" name="txt1" placeholder="inputTest">		
	</a>

    <div class="modalwrapper" id="modal">   <!-- modal -->
            <div class="modalcontainer">    
                <div class="modalcol1">
                    <label>Test 1</label>
                    <input type="checkbox" name="test_modal[]" value="1">
                    <div class="clear"></div>
                    <label>Test 2</label>
                    <input type="checkbox" name="test_modal[]" value="2">
                    <div class="clear"></div>
                    <label>Test 3</label>
                    <input type="checkbox" name="test_modal[]" value="3">
                    <div class="clear"></div>
                    <label>Test 4</label>
                    <input type="checkbox" name="test_modal[]" value="4">
                    <div class="clear"></div>
                    <label>Test 5</label>
                    <input type="checkbox" name="test_modal[]" value="5">
                    <div class="clear"></div>

                    <div class="savebutton">
                        <button class="btn1" type="button" value="Submit">Submit</button>
                    </div>
                </div> <!-- close modalcol1 -->
            </div> <!-- close modalcontainer -->
        <div class="overlay"></div>
    </div> <!-- close modalwrapper -->
</form>
&#13;
&#13;
&#13;

答案 4 :(得分:0)

将此文件放入文件中。

$('#modal_edit')。modal('hide');

希望对库布有帮助。