[英]Need help understanding jquery syntax
For this segment of code: 对于这段代码:
for (var i = 0; i < numbers.length; i++) {
var imageCrystal = $('<img>');
imageCrystal.attr('data-num', numbers[i]);
....
}
is, imageCrystal.attr('data-num', numbers[i]);
是imageCrystal.attr('data-num', numbers[i]);
making a data attribute for the image tag that was just created and giving it a class name called "data-num"
and then assigning whatever the value is at number[i]
? 为刚刚创建的图像标签创建数据属性,并为其提供一个名为"data-num"
的类名称,然后分配number[i]
处的值是什么?
Simply put 简单的说
imageCrystal.attr('data-num', numbers[i]);
is a setter 是二传手
imageCrystal.attr('data-num');
is a getter 是吸气剂
If var numbers = [100, 200, 300]
and if the img
tags are appended to the DOM
, it would look something in these lines. 如果var numbers = [100, 200, 300]
并且img
标签附加在DOM
,则它们在这些行中看起来会有些变化。
<img data-num="100" />
<img data-num="200" />
<img data-num="300" />
More info: http://api.jquery.com/attr/ 更多信息: http : //api.jquery.com/attr/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.