"볼"이라는 하나의 개체를 만듭니다. 문서로드 후, 스크립트는 개체의 12 인스턴스를 생성하고알림 기능이 각각의 색인을 표시하지 않는 이유
<ul></ul>
내 목적은 클릭 볼, 그것은 볼 인덱스를 보여줄 때이다에 많은 요소 리를 삽입합니다. 예 : 아니오 3 볼을 클릭하십시오. 3 공을 클릭하십시오. 3 볼을 클릭하면 항상 12가 표시됩니다.
죄송합니다.
function Ball(idx, parent, libra) {
this.idx = idx;
this.parent = parent;
this.libra = libra;
this.init();
}
Ball.r = 30;
Ball.prototype = {
init: function() {
var _html = $("<li><div class='ball'><span>" + this.idx + "</span></div></li>"),
pos
_this = this;
this.parent.append(_html);
this.html = _html.find(".ball");
this.html.css({
height: Ball.r * 2 + "px",
width: Ball.r * 2 + "px",
lineHeight: Ball.r * 2 + "px"
});
pos = this.html.position()
this.html.css({
left: pos.left + "px",
top: pos.top + "px",
position: "absolute"
});
this.html.mousedown(function() {alert(_this.idx)});
}
};
$("document").ready(function() {
var parent = $("#balls ul"),
libra = 1;
for (var i = 1; i < 13; i++) {
new Ball(i, parent, libra)
}
});
감사합니다. 이미 해결 됐어. – user1765418