我有一个jQuery模板(https://github.com/jquery/jquery-tmpl)和一个包含两个列表的Object()。jQuery模板,读取数据点击按钮tmplItem()
<!-- HTML -->
<table>
<thead>
<tr>
<th>
Some value
</th>
<th>
A Button
</th>
</tr>
</thead>
<tbody id="results-body">
</tbody>
</table>
<!-- HTML -->
var templateHTML = "{{each list1FromTemplate}}<tr><td>{{= Value}}</td><td><input type='button' name='alert' value='Alert' class='alert'/></td></tr>{{/each}}";
var results = new Object();
results.list1 = list1Data; //Retrieved from an ajax call
results.list2 = list2Data; //Retrieved from an ajax call
$.tmpl(templateHTML, { list1FromTemplate: results.list1, list2FromTemplate: results.list2 }).appendTo("#results-body");
//Here goes the question:
$(".alert").click(function() {
alert(
//Alert the value from {{= Value}} in the same row
);
});
一切工作正常,除了与类警报
如何从数值数据“{{=值}}” 在同一行在当带班“警报”按钮是按钮点击???
UPDATE:
即使世界的方式检索使用tmplItem()或东西的价值?
给了TD类/ ID或在跨度类/ ID包的价值,然后使用jQuery来访问它,比如'$(本) .closest( 'TR')。找到( '价值包装')。文本()' –