2017-04-02 6 views
0

私はページに一連のドロップダウンボタンを持っており、ボタンのidを持つ単一の関数をトリガーしようとしています。なぜ私の機能が呼び出されないのですか?ドロップダウンのボタンを使用してjqueryをトリガーする

<div class="dropdown"> 
    <button class="btn btn-secondary dropdown-toggle btn-sm btn-block" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> 
    Options 
    </button> 
    <div class="dropdown-menu" aria-labelledby="dropdownMenuButton"> 
    <a class="dropdown-item" href="lists/{{ $list['id'] }}/details">Edit Details</a> 
    <a class="dropdown-item" href="#">Convert to...</a> 
    <a class="dropdown-item" href="#" id= "{{ $list['id'] }}" class="copy-row">Copy</a> 
    </div> 
</div> 

とJS:

$('.copy-row').click(function(e) { 

    e.preventDefault(); 
    var token = $('meta[name="csrf-token"]').attr('content'); 

    var id = $(this).attr('id'); 
    $.ajax({url: '/lists/' + id, data: {_token:token}, type: 'PUT'}) 
    window.location.reload(); 

}); 

答えて

0

私は2つの別々のクラス文を持っていた:

<a class="dropdown-item" href="#" id= "{{ $list['id'] }}" class="copy-row">Copy</a> 

<a class="dropdown-item copy-row" href="#" id= "{{ $list['id'] }}">Copy</a> 
に変更
関連する問題