0

それらからデータを取得するためにループしたいjqueryアコーディオンがあります。

形式は次のとおりです。

<h3>Title</h3>
<div><textarea>Description</textarea></div>

名前と説明を取得できるように、各ペアをループできますか? 必要がなければ、それらを別の div にラップしたくありません。

ありがとう。

4

3 に答える 3

1

あなたはこれを行うことができます:

var things = $('h3').map(function(){ return {
    name: $(this).text(),
    description: $(this).next('div').find('textarea').val()
}}).get();

デモンストレーション

于 2013-05-24T18:19:33.057 に答える
1

h3構造が常に、次に , のdiv場合は、以下のコードを試してください。

var items = [];
$('h3').each (function () {
   items.push({
               'Name': $(this).text(), 
               'Description' : $(this).next().text()
              });
})
于 2013-05-24T18:19:33.273 に答える
1

できるよ:

$("h3").each(function() {
    console.log($(this).text()); <--- Your title text
    console.log($(this).next("div").children("textarea").text()); <--- description
});

デモ: http://jsfiddle.net/bC5Mk/

于 2013-05-24T18:19:41.163 に答える