2014-10-02 99 views
0

我想從這個頁面獲取圖像:http://m.piperlime.gap.com/product.html?dn=pp438556002&dv=1&vid=1&cid=64413&pid=438556002有沒有辦法鏈接querySelectorAll與getElementsByTagName?

現在我的代碼是:

var image = document.querySelectorAll('[data-index="0"]')[0] 
.getElementsByTagName('img')[0].src; 

有一個不太麻煩的方式來進行此事?假設我需要拉動包括data-index="0"的div。

謝謝!

編輯:我試圖讓HTML是這樣的:

<div class="gm_product_item" data-index="0" style="width: 450px; left: 0px; transition: 0ms; -webkit-transition: 0ms; -webkit-transform: translate(0px, 0px) translateZ(0px);"> 
    <img class="gm_product_itemimg" alt="Mid Rise 11&amp;#34; Skinny Product Image" src="http://www.gap.com/webcontent/0008/860/774/cn8860774.jpg"> 
</div> 
+0

@ War10ck測試非常簡單,當我在控制檯中輸入時不起作用。 – YPCrumble 2014-10-02 13:03:49

回答

2

您可以定位<img>(這是一個data-index="0"<div>)直接在您的選擇:

var image = document.querySelectorAll('[data-index="0"] img')[0].src 
+0

完美,謝謝! – YPCrumble 2014-10-02 13:09:18

相關問題