当我点击一个按钮,我的模板谁有一个表是feeded。在手柄模板中的js事件
我想要做一个动作,当我双击一个表格的一行在车把模板。
<body>
<script id="lodgerSearchResult-template" type="text/x-handlebars-template">
<div class="span12">
<table id="lodgerSearchResultTable" data-show-header="true" class="table" data-toggle="table" data-height="250">
<thead>
<tr>
<th>#</th>
<th>Nom</th>
<th>Date de naissance</th>
<th>N.A.S.</th>
<th>N.A.M.</th>
<th>Immeuble</th>
</tr>
</thead>
<tbody>
{{#each this}}
<tr>
...
...
</tr>
{{/each}}
</tbody>
</table>
</script>
</body>
<script>
$('#lodgerSearchResultTable > tbody').dblclick(function() {
alert($(this).text());
});
</script>
其实没有什么事情发生。
编辑:我把双击事件在阿贾克斯成功答案
$('#lodgerSearch').on('click', function (e) {
var searchParam = $('#srch-term').val();
var url = "http://localhost:8080/lodgers/search";
if (searchParam != "") {
url = "http://localhost:8080/lodgers/search?searchTemp=" + searchParam;
}
jQuery.ajax({
type: "GET",
url: url,
success: function (data, status, jqXHR) {
$("#lodgerSearchResult").empty().append(template(data));
// is the line i added
$('#lodgerSearchResultTable > tbody').dblclick(function() {
alert($(this).text());
});
},
error: function (jqXHR, status) {
// error handler
alert("error " + jqXHR + " - " + status);
}
});
// e.preventDefault();
});
有一个更清洁的方式做同样的事情?
测试代码用'的console.log($( '#lodgerSearchResultTable'));'在所述第二脚本的beginig块。看起来这个表格现在还没有创建。当[$(document).ready()](https://learn.jquery.com/using-jquery-core/document-ready/) – befzz
确定事件处理程序确定我点击了我的按钮,模板已加载...点击了一排桌子......没有任何事情发生,用你的控制台日志,我有一行表...我把控制台我的代码关于dblclick和那工作...所以不知道我在哪里需要把这个代码...让它正常工作。 –