来自数据绑定函数的 ID
id from data-bind function
如何从函数数据绑定上的div 获取 id?
这不起作用:
window.APP = {
models: {
court_a: kendo.observable({
court_a_touch_unit_1: function (e) {
var id = $(e.item).attr('id');
console.log(id);
},
}),
}
};
<div data-role="touch" id="court_a_touch_unit_1" data-bind="events: { touchstart: court_a_touch_unit_1 }">
<img class="unit_image" data-bind="attr: { src: images[1].url }" />
</div>
这将适用于您:
court_a_touch_unit_1: function (e) {
var id = e.sender.element.attr("id");
console.log(id);
},
或者,如果使用 data-id 更容易,请使用以下内容:
court_a_touch_unit_1: function () {
var id = $(event.target).data('id');
console.log(id);
},
<div data-role="touch" id="court_a_touch_unit_1" data-id="1" data-bind="events: { touchstart: court_a_touch_unit_1 }">
<img class="unit_image" data-id="1" data-bind="attr: { src: images[1].url }" />
</div>
您希望将数据 id 放在两个元素中,因为用户可以单击图像或div。
TCGB
相关文章:
- 是否有一个JS/jQuery函数可以获取某个类的每个元素的ID
- Javascript复选框函数:;缺少:在属性id之后"
- javascript点击函数不;不适用于ID和Class
- 将参数中类似形式的ID传递给函数click()
- JavaScript-onClick将按钮ID或单击按钮的文本传递给函数
- 不使用id的javascript中的onfocus函数
- 如何在Jquery函数中为自动完成文本区域指定一个变量作为Id
- 使用jQuery来foreach iframe-src,并通过函数获取ID和操作
- 如何传递元素's ID作为使用getElementById的函数的参数
- 将外部函数返回的id传递给内部函数
- 如何在具有相同 ID 的 Javascript 中按排序函数对关联数组进行排序
- AngularJS-点击对象,访问它's ID&以该ID作为参数激发函数
- 在具有多个值的 PHP 函数中传递 ID
- 如何在 javascript 文件函数中找到 Radnotification id
- 按类划分的元素数组 - 类型错误:$.id 不是一个函数
- HTML span id 作为 JavaScript 函数参数
- 悬停时函数在具有相同 id 的多个元素中不起作用
- 在另一个函数中使用从模板生成的 id
- 如何通过查找函数及其 ID 访问和操作 HTML 表
- id函数不起作用,如果我用户jQuery加载页面