jQuery无法更改div的属性

时间:2017-02-12 23:23:02

标签: javascript jquery html

我想使用jQuery更改vedio的文本和src似乎我无法在第一时间获得它

我的HTML标记:

<section class="main-section">
        <!-- Add Your Content Inside -->
        <div class="content">
            <div class="panel panel-default">
                <div class="panel-body">
                    <div class="embed-responsive embed-responsive-16by9">
                        @{
                            var tst = "http://www.youtube.com/embed/" + @Model.First().Lessons.First().lessonsVedio;
                        }
                        <iframe id="theVedio" class="embed-responsive-item" src=@tst allowfullscreen></iframe>
                    </div>
                </div>
            </div>

            <div class="panel panel-default">
                <div class="panel-body">
                    <div>
                        <p id="theText">tetttttststststtsbsjdbs,dbvskdvbksdbvksdbvs</p>
                    </div>
                    <a id="theMatherial" href="" class="btn btn-primary">Material</a>
                </div>
            </div>
        </div>
        <!-- /.content -->
    </section>

我的jQuery代码*:

这是有问题的部分

success: function (data) {
                alert("jQuery success");
                    alert(data[0]);
                    alert(data[1]);
                    alert(data[2]);
                    $("#thevedio").attr("src", "http://www.youtube.com/embed/" + data[0] + "?autoplay=1");
                    $("#thetext").text(data[1]);
                    $("#thematherial").attr('href', data[2]);
                    console.log($("#thevedio").attr("src"));
                    $("#thevedio").load();
                    $("#thetext").load();

                //alert(data.text);

            }

我正在测试警报并且它有所需的字符串,但是当我使用console.log时它输出undefined。

有人可以帮忙吗?感谢

1 个答案:

答案 0 :(得分:1)

jQuery标识符区分大小写,因此案例需要与HTML元素匹配。

例如:

$("#theMatherial").attr('href', data[2]);

全功能:

success: function (data) {
            alert("jQuery success");
                alert(data[0]);
                alert(data[1]);
                alert(data[2]);
                $("#theVedio").attr("src", "http://www.youtube.com/embed/" + data[0] + "?autoplay=1");
                $("#theText").text(data[1]);
                $("#theMatherial").attr('href', data[2]);
                console.log($("#theVedio").attr("src"));
                $("#theVedio").load();
                $("#theText").load();

            //alert(data.text);

        }