2015-10-22 35 views
0

我用下面的包裝我RoyalSliderRoyalSlider:無法訪問數據attribut

<a class="rsContent white" href="#"> 
    <img class="rsImg" src="#" data-color="white" width="2560" height="1440"> 
</a> 

我想檢查數據attribut的價值,爲第一rsContent所以我用下面的代碼

$('.rsContent').eq(0); OR $('.rsContent').first();

工作正常,到目前爲止,但後來當我嘗試

$('.rsContent').eq(0).data('color');$('.rsContent').eq(0).attr('class');

jQuery的返回

undefined

任何想法?

回答

0

,請查看日誌..

<html> 
    <head> 
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> 
    </head> 

    <body> 
     <a class="rsContent white" href="#"> 
      <img class="rsImg" src="#" data-color="white" width="100" height="100"> 
     </a> 
     <script> 
      console.log($('.rsContent').first().attr("class")); 
     </script> 
    </body> 
</html> 
+0

我檢查日誌:未定義 – muro

+0

似乎涉及到royalsliderplugin因爲royalsliders範圍的一切之外的工作正常。 – muro

+0

這意味着你的代碼工作正常,除非我添加royalsliderplugin。 – muro