-1

type-aud のクラスを持つ複数の div があります。div には ID がありません。ページの読み込み時に必要なため、クリック機能を実行してから (this) を使用することはできません。

各 div には file という属性があり、これを変数に割り当ててから html5 オーディオ タグに配置します。div に固有の SRC が必要です。

    var item = $('.type-aud');
        path = item.attr('file'),
        html = '<audio controls><source src="'+path+'" type="audio/mpeg" class="audio"></audio>',
        playerClass = item.find('.audio');

    if (!playerClass.hasClass('audio')) {
        item.append(html);          
    }
4

3 に答える 3

4

.each()他の方法で使用する場所で使用するだけです.click()

$('.type-aud').each(function ()
{
    var item = $(this);
    // audio tag business here
});
于 2013-01-30T16:54:01.993 に答える
1

クラス .type-aud を持つすべての div をループしてから、そのファイル属性を選択できます

$('.type-aud').each(function() {
 var item = $(this);
        path = item.attr('file'),
        html = '<audio controls><source src="'+path+'" type="audio/mpeg" class="audio"></audio>',
        playerClass = item.find('.audio');

    if (!playerClass.hasClass('audio')) {
        item.append(html);          
    }
});
于 2013-01-30T16:58:40.667 に答える
1
$('.type-aud').each(function(i,ele) {
    var item = $(ele),
        path = item.attr('file'),
        html = '<audio controls><source src="'+path+'" type="audio/mpeg" class="audio"></audio>',
        playerClass = item.find('.audio');

    if (!playerClass.is('.audio')) item.append(html);
});
于 2013-01-30T16:57:13.540 に答える