0

在 jquery 中,我在页面上获得了特定 div 的 html 并将其用作字符串。但是,请您告诉我如何删除名为“video-js”的字符串中的每个类并将其替换为另一个 div?在用具有这些值的新 div 替换它之前,我试图从每个“video-js”div 中获取一些值。

这是我到目前为止所拥有的,但它并没有写回字符串。

var getTheCurrentResults = $(".titanLoaderControlList").html();

    var obj=$(getTheCurrentResults);
    $('.video-js',obj).each(function(){

        var theID = $(this).attr("id");
        var videoSRC = $(this).find(".vjs-tech").attr("src");
        var posterSRC = $(this).find(".vjs-tech").attr("poster");

        $(this).text("<div class='playButtonContainer'><div class='playButton'><div class='playButtonSymbol'></div></div></div><div class='videoInfo' data-video-id='"+theID+"' data-source-video='"+videoSRC+"'><img class='posterInfo' src='"+posterSRC+"'></div>");
    });
4

1 回答 1

4

您应该使用.html()来替换 HTML 内容,而不是.text().

var getTheCurrentResults = $(".titanLoaderControlList").html();

var obj=$(getTheCurrentResults);
$('.video-js',obj).each(function(){

    var theID = $(this).attr("id");
    var videoSRC = $(this).find(".vjs-tech").attr("src");
    var posterSRC = $(this).find(".vjs-tech").attr("poster");

    $(this).html("<div class='playButtonContainer'><div class='playButton'><div class='playButtonSymbol'></div></div></div><div class='videoInfo' data-video-id='"+theID+"' data-source-video='"+videoSRC+"'><img class='posterInfo' src='"+posterSRC+"'></div>");
});
于 2013-07-08T14:33:06.710 回答