2013-05-15 43 views
-1

我有這個代碼獲取圖像的URL內裏

<li> 
    <div class="product-container"> 
     <div class="product-imgs"> 
      <img src="https://xxxx.png"> 
     </div> 
     <div class="product-desc product-desc-top"> 
      <h3>Kitten 1</h3> 
      <p class="title-desc">This is kitten kitten kitten kitten kitten kitten</p> 
     </div> 
     <div class="product-desc product-desc-bottom"> 
      <h4>$ 999</h4> 
      <p class="count-buyers">1 buyer</p> 
     </div> 
    </div> 
</li> 

我有很多的<li>,那我想是這樣的條件:

如果我點擊<li>我想獲取img網址。我也想獲得h3,p,h4,p的內容。




是否有可能使用jQuery處理這種情況?

感謝

+1

在它的當前狀態,你的問題是沒有意義的(對我來說)。如果可能的話,請嘗試重新編寫它,因爲我甚至無法開始理解它足以進行編輯。 – user1596138

+3

是的,完全有可能。發佈你到目前爲止已經試過的.. – techfoobar

+0

@JosiahSouth對不起,我的英語技能不夠好。 :) 我們的朋友Binhvi&cherhan得到了答案。 – Hariawan

回答

3

試一試:

//獲取圖片url和標籤clone。

$(function() { 
      $("li").click(function(){ 
       var imgUrl = $(this).find("img").attr("src"); 
       var h3 = $(this).find("h3").clone(); 
       var h4 = $(this).find("h4").clone(); 
       var title_desc = $(this).find(".title-desc").clone(); 
       var count_buyers = $(this).find(".count-buyers").clone(); 
      }) 
     }); 

//獲取圖片URL和標籤上的文字。

$(function() { 
      $("li").click(function(){ 
       var imgUrl = $(this).find("img").attr("src"); 
       var h3 = $(this).find("h3").text(); 
       var h4 = $(this).find("h4").text(); 
       var title_desc = $(this).find(".title-desc").text(); 
       var count_buyers = $(this).find(".count-buyers").text(); 
      }) 
     }); 
1

試試這個:

$('li div:first-child div img').attr('src'); 

var value = $('li div:nth-child(2) div h3').html(); 

var value2 = $('li div:nth-child(2) div h4').html(); 

等。

+1

請對-1加入評論 –

+0

啊!我現在明白這個問題。這不應該是-1。 + 1-ING。 – user1596138

2

你可以做到這一點

$('li').click(function() 
    { 
    var img = $(this).find('img'); 
var url = $(img).attr('src');   
var h3 = $(this).find('h3').html(); 
    }); 

工作的jsfiddle:http://jsfiddle.net/WZL7J/1/