0

您好,我正在尝试从 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。

4

1 回答 1

0

您的函数需要一个参数:

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

希望这可以帮助。

于 2014-09-02T12:37:47.643 回答