-1

私はこのコードを持っています

<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 の URL を取得したいと思います。また、h3、p、h4、p コンテンツを取得したいと考えていました。




jQueryを使用してこの条件を処理することは可能ですか?

ありがとう

4

3 に答える 3

4

それを試してみてください:

// 画像の URL とタグのクローンを取得します。

 $(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();
            })
        });
于 2013-05-15T06:01:32.177 に答える
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/

于 2013-05-15T06:02:04.107 に答える
0

これを試して:

$('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();

等々。

于 2013-05-15T05:58:22.250 に答える