【问题标题】:Changing data and value from an object in an href从 href 中的对象更改数据和值
【发布时间】:2014-09-02 12:25:20
【问题描述】:

您好,我正在尝试从 twitch 更改嵌入代码中的对象数据和参数值。 我对 javascript 不是很好,可以使用一些帮助。 实际上我的脚本使用和输入按钮,但我想用链接刷新抽搐视频

我的 HTML 代码:

<div id="streamHolder">
    <object type="application/x-shockwave-flash" height="378" width="620" id="live_embed_player_flash" bgcolor="#000000">
        <param name="allowFullScreen" value="true" />
        <param name="allowScriptAccess" value="always" />
        <param name="allowNetworking" value="all" />
        <param name="movie" value="http://www.twitch.tv/widgets/live_embed_player.swf" />
        <param id="param" name="flashvars" />
    </object>
</div>
<div id="buttons">
    <input type="text" id="streamName" placeholder="Enter Streamer Name Here" style="width:12em;">
    <input type="button" id="button1" onclick="changestream1();" value="Change Stream">
</div>

<a href="#" onclick="changestream1(riotgames);" id="streamName" value="Change Stream">riotgames</a>

我的 Javascript 代码:

function changestream1() {
    var streamInput = document.getElementById('streamName').value;
    var streamIn = ''; //This variable is not defined yet used on the last line of this block;
    var object = document.getElementById('live_embed_player_flash');
    var param = document.getElementById('param');
    object.setAttribute("data", "http://www.twitch.tv/widgets/live_embed_player.swf?channel=" + streamInput);
    param.setAttribute("value", "hostname=www.twitch.tv&channel=" + streamInput + "&auto_play=true&start_volume=25" + streamIn);
}

如果您需要了解我的想法,请按链接:D JsFiddle

问候,Rac3Mul。

【问题讨论】:

    标签: javascript html twitch


    【解决方案1】:

    你的函数需要一个参数:

    function changestream1(parameter) {
            var streamInput;
            if(parameter == riotgames)
            {
                  streamInput = riotgames;
            }
            else
            {
                  streamInput = whatever;
             }
            //do something
    }
    

    希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-12-06
      • 1970-01-01
      • 2014-03-24
      • 2019-05-15
      • 1970-01-01
      • 2012-03-14
      • 1970-01-01
      • 2011-05-30
      相关资源
      最近更新 更多