如何解决jQuery不会获取我正在单击的元素的当前值只有第一个会显示,而我是使用Handlebars生成的
我正在做一个时间表,并且Jquery选择器和Handlebars一起出现问题。我生成表的许多行并尝试获取数据属性,但是它仅与DOM上打印的第一个元素一起使用。我也尝试过将JQuery函数放在$(document).on()内,但是没有用。
这是我正在使用的车把的脚本。
<script id="entry-template" type="text/x-handlebars-template">
<tr>
<th scope="row">{{day}}</th>
<td><input id="first{{id}}" class="table-success" type="time"></td>
<td><input id="second{{id}}" class="table-danger" type="time"></td>
<td><input id="third{{id}}" class="table-success" type="time"></td>
<td><input id="fourth{{id}}" class="table-danger" type="time"></td>
<td id="sum"><button data-attribute="{{id}}">Somma</button><span id="result"></span></td>
</tr>
</script>
这是应该具有数据属性的jquery函数。
$("#sum").click(function(){
var currentLine = $(this).find("button").attr("data-attribute");
console.log(currentLine);
});
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。