为什么我的代码不粘贴我的 iframe src?在 HTML 中它只是空的。
<iframe id="Stream" src="" class="col-sm-12" frameborder="0" scrolling="no"></iframe>
<iframe id="Chat" src="" frameborder="0" scrolling="no"></iframe>
$('#Stream').attr("https://player.twitch.tv/?channel=" + channel, url)
$('#Chat').attr("https://www.twitch.tv/" + channel + "/chat?popout=", url)
最佳答案
您调用 attr()
方法的语法不正确。第一个参数是属性的名称,第二个应该是您要设置的值。在可能的情况下,最好使用 prop()
方法,就像在本例中一样。
$('#Stream').prop('src', "https://player.twitch.tv/?channel=" + channel);
$('#Chat').prop('src', "https://www.twitch.tv/" + channel + "/chat?popout=");
请注意,如果请求的域不允许使用 X-Frame-Options
在第三方网站的 iframe 中呈现自身,这可能仍然无法正常工作。
关于javascript - 使用 jQuery 编辑 iframe src,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36985362/