Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用JavaScript更改iframe src_Javascript_Iframe - Fatal编程技术网

使用JavaScript更改iframe src

使用JavaScript更改iframe src,javascript,iframe,Javascript,Iframe,我有三个不同的页面player_lo.html,player_hi.html和player_med.html 这三个页面是不同质量的流播放器流页面。我想使用JavaScript更改iframe的源代码 我有这个脚本,但它不起作用: <a href="/player/player_lo.html" class="button grey" onclick="$('#player').attr('src', 'player_lo.html'); $(this).parent().find('a'

我有三个不同的页面
player_lo.html
player_hi.html
player_med.html

这三个页面是不同质量的流播放器流页面。我想使用JavaScript更改
iframe
的源代码

我有这个脚本,但它不起作用:

<a href="/player/player_lo.html" class="button grey" onclick="$('#player').attr('src', 'player_lo.html'); $(this).parent().find('a').removeClass('red'); $(this).parent().find('a').addClass('grey'); $(this).addClass('red').removeClass('grey'); return false;">Low Quality</a>
<a href="/player/player_med.html" class="button red" onclick="$('#player').attr('src', 'player_med.html'); $(this).parent().find('a').removeClass('red'); $(this).parent().find('a').addClass('grey'); $(this).addClass('red').removeClass('grey'); return false;">medium quality</a>
<a href="/player/player_hi.html" class="button grey" onclick="$('#player').attr('src', 'player_hi.html'); $(this).parent().find('a').removeClass('red'); $(this).parent().find('a').addClass('grey'); $(this).addClass('red').removeClass('grey'); return false;">high quality/a>



当你点击ззззггзззззззззггггззззззззззззгз。这可能是你的问题

  • 尝试在JavaScript中使用相同的(绝对)路径
  • 确保页面确实存在
  • 密切关注浏览器的错误控制台,看看哪里出了问题
您可能会发现其他有用的提示:

尝试使用一个描述差异的类,例如活动类,而不是名为的红色类和灰色类(这两个类是互斥类,意味着按钮不能同时属于这两个类)。然后,使用CSS将按钮样式设置为默认为灰色,或在类
处于活动状态时设置为红色。附加的优点是颜色不在类名中编码(例如,您可以在将来将活动颜色更改为蓝色或其他颜色)

另外,不要使用inline
onclick
属性,而是尝试将事件处理程序绑定到
。这样,您就可以轻松地使用



当它不起作用时会发生什么?是的,它是Iframe中的播放器,@DarkXphenomenon nothing,我也有Iframe,当我单击时应该是更改质量(来源)您可以尝试在链接中使用target=“Iframe\u name”,那可能行。你能给我更多的信息做什么吗?:)我是JS的新手:)@AngelI不确定这就是你要找的,或者它是否能解决你的问题。我想说的是为iframe命名,比如:name=“player\u iframe”。在每个链接中只需添加以下内容:target=“player\u iframe”。设置链接href加载到iframe的目标。