質問

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
});
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top