我不了解.data()?
这是两个div: -
<div id="dataObjects">
<div id="dataGetterClone"></div>
</div>
这是我的代码: -
for (var i = 0; i < 4; i++) {
var elementid = "dataGetter";
$("#" + elementid + "Clone")
.clone()
.attr('id',elementid + i.toString())
.addClass("newItem")
.data('dflt_internal_ID' ,"")
.data('dflt_elem_category' ,"Category")
.data('dflt_elem_type' ,"Standard")
.data('dflt_elem_name' ,"Getter " + i.toString())
.data('dflt_elem_top' ,20)
.data('dflt_elem_left' ,40)
.data('dflt_elem_height' ,60)
.data('dflt_elem_width' ,80)
.appendTo($("#dataObjects"));
}
// keep track of number of changes to be saved, and display error later if there are none
var itemCount = 0;
// prepare items to be inserted
var createdOn = new Date();
$( "#dataObjects > .newItem" ).each( function() {
$(this).data("created_by", 57);
$(this).data("created_on", createdOn);
itemCount++;
alert($(this).data().count);
});
alert("count of inserts " + itemCount);
Here是我的小提琴。
为什么要提醒($(this).data()。count);返回“未定义”?