douliao5467 2017-04-16 13:28
浏览 48
已采纳

在Laravel中单击关闭时,以模态清除数据

I have a modal (Bootstrap) for creating a new product. When I click the "close" button, which creates a new product, the old data still does not clear from the modal.

My code:

<div class="modal fade" id="product" role="dialog" aria-hidden="true" data-target="#myModal"   data-backdrop="static"  data-keyboard="false" >
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">&times;</button>
                <h4 class="modal-title">Create new product</h4>
            </div>
            <div class="modal-body">
                <form role="form" action="{{ route('admin.product.addProduct')}}" method="post" id="frmProduct">
                    {{ csrf_field() }}
                    <input type="hidden" name="_token" value="{{ csrf_token() }}">
                    <div class="row">
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="">Product Name</label>
                                <input type="text" class="form-control" id="" name="product_name">
                            </div>
                            <div class="form-group">
                                <label for="">Product Type</label>
                                <input type="text" class="form-control" id="" name="product_type_id">
                            </div>
                            <div class="form-group">
                                <label for="">Price</label>
                                <input type="text" class="form-control" id="" name="price">
                            </div>
                            <div class="form-group">
                                <label for="">Status</label>
                                <select class="form-control input-sm m-bot15" id="" name="status">
                                    <option value="0">Inactive</option>
                                    <option value="1">Active</option>
                                </select>
                            </div>
                            <div class="form-group">
                                <label for="img">Image</label>

                                <div class="input-group">
                                    <span class="input-group-btn">
                                        <span class="btn btn-default btn-file">
                                            Choose <input type="file" id="imgInp">
                                        </span>
                                    </span>
                                    <input type="text" class="form-control" name="product_image" readonly>
                                </div>
                                <img id='img-upload' class="image_responsive" />
                            </div>
                        </div>

                    <div class="col-md-6">
                        <div class="form-group">
                            <label for="">Description</label>
                            <textarea class="form-control" id="" name="description"></textarea>
                        </div>
                        <div class="form-group">
                            <label for="">Note</label>
                            <textarea class="form-control" id="" name="addition_information"></textarea>
                        </div>

                    </div>
                </div>
            </div>
            <div class="modal-footer">
                    <input type="submit" value="Save" class="btn btn-success">
            <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            </div>
        </form>
    </div>

</div>
</div>

How can I clear the data when closing the modal?

  • 写回答

2条回答 默认 最新

  • ds9567 2017-04-16 13:38
    关注

    You can add event listener to your close button by adding an id to your close button for example id=close-btn:

    document.getElementById("close-btn").addEventListener("click", function(){ 
       document.getElementById("frmProduct").reset();
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器