JQuery DOM获取绑定属性
JQuery DOM get Binded attribudes
我有代码
$(".showerPr").on('click', '.prototypeDiv',function(){
});
HTML看起来像
<div class='showerPr' data-id='3'>
<div class='prototypeDiv' data-id='5'><div>
</div>
是否有一些解决方案分别获得淋浴数据id和prototypepedv数据id ?
像somethink
$(this).attr('data-id');
$(this).before().attr('data-id');
:-D谢谢。
.showerPr
不是before()
即.prototypeDiv
元素,它是父元素
var proto = $(this).data('id');
var shower = $(this).parent().data('id');
$(".showerPr").on('click', '.prototypeDiv',function(){
var proto = $(this).data('id');
var shower = $(this).parent().data('id');
$('#result').html('prototypeDiv : ' + proto + '<br />' + 'showerPr : ' + shower)
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class='showerPr' data-id='3'>
<div class='prototypeDiv' data-id='5'>Click Me !!!<div>
</div>
<br/><br/>
<div id="result"></div>
@adeneo是正确的,.showerPr
是父元素。你可能想要检查jQuery的遍历方法。
下面是代码片段。
$(".prototypeDiv").on('click', function(){
alert($(this).data('id'));
alert($(this).parent().data('id'));
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class='showerPr' data-id='3'>
<div class='prototypeDiv' data-id='5'>123<div>
</div>
相关文章:
- IE8中的Ember.js(1.0pre)属性绑定错误
- LiveCycle Xml属性绑定
- angular2中具有属性绑定的字符串串联
- Javascript数据将元素属性绑定到URL中的锚href
- 从服务器端将属性绑定到套接字对象;似乎不能正常工作
- AngularJs 将模型属性绑定到复选框
- 属性绑定中的 Javascript 或 Query in Birt
- AngularJS指令将名称属性绑定到模板元素
- React JS - uncatch TypeError:无法读取未定义的属性“绑定”
- ng-options 模型基于属性绑定
- ReactJS 无法读取未定义的属性“绑定”
- 使用$scope属性绑定ng-includ-src
- 使用Knockout.js如何将Date属性绑定到HTML5日期选择器
- AngularJS:将角度服务属性绑定到范围
- 为什么可以't我使用原型将属性绑定到对象
- AngularJs:将作用域对象的属性绑定到指令
- 通过公共属性绑定指令实例
- EmberJS属性绑定
- 当使用映射时,属性绑定被破坏
- Angularjs属性绑定优先级