2014-09-04 85 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