underscore.js生成テンプレート用のイベントハンドラー
-
28-10-2019 - |
質問
JSコードの残りの部分とは別のファイルにテンプレートがあります。テンプレートのためにEventHandlersをやろうとしています(たとえば、以下のオンクリックイベントなど)が、機能しません。誰かが私がこれをどのように解決できるか教えてもらえますか?
var output = _.template($('#myTemplate').html(), {myData});
$('#content').html(output);
//This doesn't work
$('#myButton').click(function(){
//Do something
});
//My template
<script type="text/template" id="myTemplate">
<h2><%= myTitle %></h2>
<button id="myButton">Button</button>
</script>
解決
$('#myButton').live('click', function(){
//Do something
});
所属していません StackOverflow