2017-01-05 12 views
0

現在、クローム拡張機能を開発中です。私のクロムエクステンションにはボタンが付いたテーブルがあります。私のaddress.jsの私のボタンID "copy"文句を言わないが、これは私の自宅で警告jqueryを使用してボタンが動作しない

をトリガし、なぜしかし残念ながら、私のボタンが動作しませんし、コンソールにはエラーがありません。..

私の質問は私のChromeの拡張機能

<!DOCTYPE html> 
<html lang="en"> 
    <head> 
    <meta charset="utf-8"> 
    <meta http-equiv="X-UA-Compatible" content="IE=edge"> 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 

    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"> 


    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> 

    <script src= "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" ></script> 

<script type="text/javascript" src = "address.js"></script> 

    </head> 
    <body> 
    <p><br/><br/></p> 
    <div class = "container"> 
      <table id="example" class = "table table-bordered table-striped table-hover"> 
       <thead> 
        <tr> 
        <th>Video Name</th> 
        <th>File Name</th> 
        <th>Copy</th> 

        </tr> 

       </thead> 

      </table> 
    </div> 



    </body> 
</html> 

そして、これが私のaddress.js

ありでの.html
+1

を試してみてください"、"#copy "、function(){' – Satpal

答えて

2

あなたはdynamically

$(document).on("click","#copy",function(){ 
    alert('copied'); 
}); 

イベントをトリガする必要があり、それがどのように機能するかを理解するためにevent delegationについては、こちらをご覧ください。ダイナミックDOMによって

+0

これまでにありがとうございました。 – VLR

1

動的に追加された要素については、クリックを少し違うようにバインドしています(イベント委任)。これを試してみてください:

$(document).on("click", "#copy", function() { 
    alert('copied'); 
}); 
1

は、[イベント委任](http://learn.jquery.com/events/event-delegation/)を使用するコード `$(文書).on("クリックを学び、この

$(document).on("click", "#copy", function() { 
    alert('copy'); 

}); 
関連する問題