[問題] 如何傳值

看板Ajax作者 (有時會倔強過了頭...)時間14年前 (2011/09/06 17:45), 編輯推噓0(007)
留言7則, 3人參與, 最新討論串1/1
想請教各位前輩~ 我有一個class 叫 CarouselItem 在這裡頭我想要加入圖片的Width and Height Data 所以我用_image.onload的方式去取得圖片尺寸 但是想很久就是不曉得該怎麼把值給傳出來 想請大家給我意見<(_ _)> 程式碼如下,謝謝 function CarouselItem(Parent, HREF, ImageSRC, ImageAlt) { this._parent = Parent; this._ID = this._parent._ID + 'Item' + this._parent._items.length; this._href = HREF; this._element = null; this._position = new Vector2D(0, 0); this._size = this._parent._itemSize.Clone(); this._image = new Image(); this._imageH = 0; this._imageW = 0; this._image.onload = function () { this._imageW = this.width; //這是錯的 i konw> < this._imageH = this.height; } 。 。 。 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 210.63.100.2 ※ 編輯: Qiu0 來自: 210.63.100.2 (09/06 17:47)

09/06 18:45, , 1F
this._imageW和this.width的this是不一樣的
09/06 18:45, 1F

09/07 11:02, , 2F
I know>< 所以才苦惱不曉得怎麼取出來餵給this._imageW
09/07 11:02, 2F

09/07 11:11, , 3F
在this._image.onload = function () {這行上面寫
09/07 11:11, 3F

09/07 11:11, , 4F
var that = this ; 在this._image.onload = function () {
09/07 11:11, 4F

09/07 11:12, , 5F
這行下面用that._imageW = this.width;
09/07 11:12, 5F

09/07 11:13, , 6F
或多一個參數x this._image.onload = function (x) {
09/07 11:13, 6F

09/07 11:20, , 7F
不行不能用參數傳
09/07 11:20, 7F
文章代碼(AID): #1EPUlDAg (Ajax)
文章代碼(AID): #1EPUlDAg (Ajax)