简体   繁体   English

未为Bootstrap Modal定义Javascript函数

[英]Javascript function not defined for Bootstrap Modal

I want to make a modal edit form to show up after clicking certain button in HTML. 我想制作一个模式编辑表单,以在单击HTML中的某些按钮后显示。 This is the javascript : 这是javascript:

<script>
    var edit;

    jQuery( document ).ready(function( $ ) {
        // Edit Data (Modal and function edit data)
        edit = function edit(id, un, nl, em, nh, st) {
            //$('#myModal').attr('action', '{{ url('user/edit') }}/'+id;

            $('#footer_action_button').text("Update");
            $('#footer_action_button').addClass('yellow btn-outline');
            $('.btn').addClass('edit');
            $('.modal-title').text('Edit Pengguna');
            $('.delete').hide();
            $('.form-horizontal').show();
            $('#un').val(un);
            $('#nl').val(nl);
            $('#em').val(em);
            $('#pw').attr('placeholder', 'Isi Jika Ingin Diganti');
            $('#nh').val(nh);
            $('#st').val(st);
            $('#myModal').modal('show');
        }
    });
</script>

With this code, the modal form shows up, but I can't do the update because there's no url involved. 使用此代码,将显示模式形式,但由于不涉及url,所以无法进行更新。 And so, when I add modal action (simply remove the comment tag) I got error that my edit function is not defined. 因此,当我添加模式操作(仅删除注释标签)时,出现错误,提示我的编辑功能未定义。 For now I only write my JS code in this question beacuse I don't see other codes related, but let me know if you need an update. 现在,我只在此问题中编写我的JS代码,因为我看不到其他相关代码,但是如果您需要更新,请告诉我。

Regards. 问候。

you can create a anonymous function to get the popup.syntax for commented part in your code is wrong i have updated it and kept it commented.Try like this: 您可以创建一个匿名函数来获取代码中已注释部分的popup.syntax是错误的,我已对其进行了更新并对其进行了注释。尝试如下操作:

var edit = function(id, un, nl, em, nh, st) {
            // $('#myModal').attr('action', "{{ url('user/edit') }}/"+id);

            $('#footer_action_button').text("Update");
            $('#footer_action_button').addClass('yellow btn-outline');
            $('.btn').addClass('edit');
            $('.modal-title').text('Edit Pengguna');
            $('.delete').hide();
            $('.form-horizontal').show();
            $('#un').val(un);
            $('#nl').val(nl);
            $('#em').val(em);
            $('#pw').attr('placeholder', 'Isi Jika Ingin Diganti');
            $('#nh').val(nh);
            $('#st').val(st);
            $('#myModal').modal('show');
        };

SEE A DEMO BELOW: 查看下面的演示:

 var edit = function(id, un, nl, em, nh, st) { $('#myModal').attr('action', "{{ url('user/edit') }}/"+id); $('#myModal').modal('show'); }; edit('id','un','nl','em','nh','st');// this test is only for example you pass your data here 
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> <div id="myModal" class="modal fade" role="dialog"> <div class="modal-dialog"> <!-- Modal content--> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal">&times;</button> <h4 class="modal-title">Modal Header</h4> </div> <div class="modal-body"> <p>Some text in the modal.</p> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> </div> </div> </div> </div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM