我无法让我的事件处理程序触发。我将 JSON 调用到页面中,如下所示。然后我希望能够单击我创建的按钮之一,该按钮将执行“你好”警报。它适用于页面上的所有其他元素,但不适用于<button>
.
任何人都可以帮忙吗?
测试.js
$(document).ready(function() {
$.getJSON('/api/v1/recipe/?format=json', function(data) {
$.each(data.objects, function(i, recipe) {
$('table#recipes').append('<tr><td>' + recipe.title + '</td><td>' + recipe.ingredients + '</td><td>' + recipe.method + '</td><td><button class="btn" type="button" id="rmv">remove</button></td></tr>');
});
});
$('rmv').on('click', function() {
alert('hello there!');
});
});
食谱.html
{% extends 'base.html' %}
{% block content %}
<div class="container-fluid">
<div class="row-fluid">
<div class="span6">
<form action='' method="post">{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="go baby!">
</form>
</div>
<div class="span6">
<table class="table table-striped table-bordered" id="recipes">
<tr>
<th>Title</th>
<th>Ingredients</th>
<th>Method</th>
<th>Remove</th>
</tr>
</table>
</div>
</div>
</div>
{% block recipes %}{% endblock recipes %}
{% endblock content %}