动态绑定元标记 jquery

Dynamically Bind MetaTag Jquery

本文关键字:jquery 动态绑定      更新时间:2023-09-26

大家好,我正在尝试使用 Jquery 动态绑定内容。我关注了许多来自堆栈溢出站点的讨论比如如何在不使用jquery追加的情况下插入元标记?

以下是我尝试的代码。我不知道我哪里做错了任何帮助都会得到赞赏。

<head>
    <meta property="og:description" content="sdgds"/>
    <meta property="og:title" content="sfsfds"/>
    <meta property='og:image' content="http://i1.ytimg.com/vi/v9ao-fGMVz8/maxresdefault.jpg" />
    <meta property='og:video' content="http://abcd.azurewebsites.net/api/Video/?video_id=1" />
     <meta property="og:video:type" content="application/x-shockwave-flash" />
     <meta property="og:video:width" content="1920" />
     <meta property="og:video:height" content="1080" />
    <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
    <script>
    $(document).ready(function() {
            var first = getUrlVars()["id"];
            $.ajax({
            type: "Get",
            url: 'http://abcd.azurewebsites.net/api/Video/?video_id=1',
            success: function (data) {  
                alert("Hello");
                var tv_main_channel = $('#tv_main_channel');
                data="http://abcd.azurewebsites.net/Content/movie.mp4";
                tv_main_channel.attr("src", data);
                var video_block = $('#video');
                video_block.load();
                $('meta[name=og'':description]').attr('content', "This is des");
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
            console.log(JSON.stringify(XMLHttpRequest));
            }
            });
        });
    function getUrlVars()
    {
        var vars = [], hash;
        var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
        for(var i = 0; i < hashes.length; i++)
        {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
        }
        return vars;
    }
    </script>


</head>

你使用的jquery版本不适合这样做。使用较新的版本。

<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.0-rc1/jquery.js"></script>