2017-01-10 27 views
0

HTMLの特定のボタンをクリックした後に表示するモーダル編集フォームを作成します。これは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> 

、モーダルフォームが現れますが、関係する一切のURLがありませんので、私は、更新を行うことはできません。そして、モーダルアクション(単にコメントタグを削除する)を追加すると、編集機能が定義されていないというエラーが表示されます。今のところ私はJSコードをこの問題に書いています。関連するコードは他にはありませんが、アップデートが必要な場合は教えてください。

よろしくお願いいたします。

+0

変数に他のいくつかの名前を付けます。変数名と関数名は同じです。したがって、問題 –

+0

または機能を匿名にする –

答えて

1

あなたのコード内のコメント部分のpopup.syntaxを取得するために無名関数を作成することができますが間違っている私はそれを更新して、それがこれを好きcommented.Tryまま:

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'); 
     }; 

BELOW DEMOを参照してください。

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> 
 

+0

ありがとう、それは動作しますが、私はモーダルのコメントを外してURLにリンクすることはできません。それは編集が関数ではないことを示しています... –

+0

@RayanSuryadikaraコード内のcommnted部分が間違っています。私はそれを更新しました。 –

関連する問題