2014-09-04 86 views
0

我有使用$我下面的代碼中(這)獲得所需值的一些問題:的jQuery越來越需要從價值返回的對象

.... 
open: function() { 
    console.log('Popup is opened'); 
    console.log($(this).get(0).src); 
}, 
.... 

我也試過:

.... 
open: function() { 
    console.log('Popup is opened'); 
    console.log($(this)[0].src); 
}, 
.... 

但我似乎沒有正確的結構以獲得該值。

對象是:

{ 
"0": { 
    "isIE7": false, 
    "isIE8": false, 
    "isLowIE": false, 
    "isAndroid": false, 
    "isIOS": false, 
    "supportsTransition": true, 
    "probablyMobile": false, 
    "popupsCache": { 

    }, 
    "items": [{ 
     "el": { 
      "0": { 
       "jQuery111108245181320528183": 1 
      }, 
      "context": { 
       "jQuery111108245181320528183": 1 
      }, 
      "length": 1 
     }, 
     "src": "http://linkishere.com/Dolphin.jpg", 
     "type": "image", 
     "index": 0, 
     "parsed": true, 
     "img": { 
      "0": { 
       "jQuery111108245181320528183": 20 
      }, 
      "context": { 
       "jQuery111108245181320528183": 20 
      }, 
      "length": 1 
     }, 
     "hasSize": true, 
     "preloaded": true 
    }], 
Etc etc..... 

我缺少什麼?

回答

0

您的項目對象包含src財產及其所屬Item那麼你應該使用

console.log(obj[0].items[0].src); 

這裏是Fiddle Example

+1

你猜對了感謝阿南特。 ! – StealthRT 2014-09-04 05:08:16

0

使用$(this).attr('src')$(this)[0].src

+0

給我*不確定* – StealthRT 2014-09-04 04:37:22

+0

u能告訴我們完整的javascript代碼,請 – kefy 2014-09-04 04:40:03

1

,如果你有以上的JSON結構,那麼

使用this["0"]["items"]["0"].src$(this)[0].src

this[0].items[0].src 
+0

爲什麼-1 :(??????? – 2014-09-04 05:54:20

0

,如果你的這個對象是正確的,因爲你描述。你可以不jQuery的訪問SRC如下:

console.log(this[0].items[0].src); 
+0

TypeError:This [0] is undefined – StealthRT 2014-09-04 05:07:20

+0

您的此對象有一些問題或者您對此對象的表示不正確。請嘗試使用 登錄console.log(JSON.stringify(this)); if code implementation是在jquery事件範圍內,這個對象可以與jquery對象混淆 – KyawLay 2014-09-04 05:12:51