簡體   English   中英

從抽搐更改對象的數據和嵌入內部參數的值

[英]Changing the data of a object and the value of a parameter inside the embed from twitch

您好,我正在嘗試從twitch更改嵌入代碼內的對象數據和參數值。
我對javascript不太滿意,可以使用一些幫助。
我做研究沒有運氣。
感謝所有幫助:)


我要更改的嵌入代碼(這是新的嵌入代碼,無任何編輯)

function changestream1(){
    var streamIn = document.getElementById('stream1').value;
    var objData= document.getElementById('live_embed_player_flash');
    var param = document.getElementById('param');

    objData.setAttribute("data", "http://www.twitch.tv/widgets/live_embed_player.swf?channel=" + streamIn); 
    param.setAttribute("value", "hostname=www.twitch.tv&channel=" + streamIn + "&auto_play=true&start_volume=25"); 
}


這是我到目前為止的js,它不起作用:P(記住我是js的菜鳥)

 function changestream1(){ var streamIn = document.getElementById('stream1').value; var objData= document.getElementById('live_embed_player_flash'); var param = document.getElementById('param'); objData.setAttribute("data", "http://www.twitch.tv/widgets/live_embed_player.swf?channel=" + streamIn); param.setAttribute("value", "hostname=www.twitch.tv&channel=" + streamIn + "&auto_play=true&start_volume=25"); } 

這個想法是js將在對象中創建數據並在參數中創建值。


如果您需要我如何思考的視覺效果,請按Link:D
JsFiddle

鏈接到將要使用的網站
抽搐者

您在這里缺少一個+號streamIn + “&auto_play = true&start_volume = 25”

您應該檢查所有代碼,還有其他錯誤,例如在調用cameCase時以小寫字母命名該函數,檢查每個變量,安裝Firebug並查看控制台中的日志...

這應該工作

<script type="text/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);
}
</script>
<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>
<p>The name you enter will get put where the "streamInput" variable is in the javascript
<br>that is the general idea atleast</p>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM