Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/381.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更改JavaScript_Javascript_Html - Fatal编程技术网

用JavaScript更改JavaScript

用JavaScript更改JavaScript,javascript,html,Javascript,Html,我需要一个按钮来更改它的URL以匹配屏幕上显示的iframe。我在这里面临的问题是如何使用JavaScript更改按钮的URL 以下是我目前的情况: <button id="t7"onclick="t7()">Full Pilot</button><br> function f0() {document.getElementById('i').src="https://pilot.wright.edu/d2l/home";} function

我需要一个按钮来更改它的URL以匹配屏幕上显示的iframe。我在这里面临的问题是如何使用JavaScript更改按钮的URL

以下是我目前的情况:

   <button id="t7"onclick="t7()">Full Pilot</button><br>
    function f0() {document.getElementById('i').src="https://pilot.wright.edu/d2l/home";}
  function f1() {document.getElementById('i').src="https://pilot.wright.edu/d2l/home/159483";}
    function f2() {document.getElementById('i').src="https://pilot.wright.edu/d2l/le/content/219408/Home";}
   function f3() {document.getElementById('i').src="https://pilot.wright.edu/d2l/home/159465";}
   function f4() {document.getElementById('i').src="https://pilot.wright.edu/d2l/home/219301";}
    function f5() {document.getElementById('i').src="https://pilot.wright.edu/d2l/home/159463";}

尝试
document.getElementById('t7')。onclick=“…”
更改“url”。

首先,按钮应具有“类型”属性,不同的浏览器可能对按钮元素具有不同的默认值

其次,按钮没有src属性,因此您不能更改按钮的src,请尝试使用

功能iload(obj){
document.getElementById(“t7”).href=obj.src;
}
更新:无href方法

<iframe src="http://www.mysite.com" onload="iload(this)"></iframe>
<button type="button" id="t7">Full Pivot</a>
<script>
    function iload(obj) {
        document.getElementById("t7").onclick = function() {
            window.location.href=obj.src;
        }
    }
</script>

全枢轴
功能iload(obj){
document.getElementById(“t7”).onclick=function(){
window.location.href=obj.src;
}
}
或者,一个较短的方法

<iframe src="http://www.mysite.com" id="the_iframe"></iframe>
<button type="button" onclick="iload">Full Pivot</a>
<script>
    function iload() {
        window.location.href=document.getElementById("the_iframe").src;
    }
</script>

全枢轴
函数iload(){
window.location.href=document.getElementById(“theiframe”).src;
}
JavaScript: 第一次按钮按下:

function f0(){document.getElementById('i').src="https://pilot.wright.edu/d2l/home";document.getElementById('o').innerHTML="https://pilot.wright.edu/d2l/home"}
HTML:

我基本上只是添加了一个段落节点,并将URL共享到按钮的innerHTML


感谢所有回答的人

你能给我们展示一下你迄今为止所做的尝试,并发布一个演示来重现你的特定问题吗?问题是我甚至不知道如何尝试。然后你可能需要做更多的研究。我们在询问代码的问题中期待代码。请尝试了解JavaScript的一般知识。还可以看到,当你得到一些代码时,你已经成功了一半。好吧,我刚才尝试过使用它,但它仍然将src设置为文件路径,而不是它所显示的URL。好吧,我想对object.src做一点澄清,我正试图避免使用超链接buttons@CMS2我编辑了答案,请看一看。关于
obj.src
iload(this)
将iframe对象解析为obj变量。因此,当您调用
obj.src
时,它将返回iframe的
src
<iframe src="http://www.mysite.com" id="the_iframe"></iframe>
<button type="button" onclick="iload">Full Pivot</a>
<script>
    function iload() {
        window.location.href=document.getElementById("the_iframe").src;
    }
</script>
function f0(){document.getElementById('i').src="https://pilot.wright.edu/d2l/home";document.getElementById('o').innerHTML="https://pilot.wright.edu/d2l/home"}
   <p id="o">https://pilot.wright.edu/d2l/home</p>
function t7() {window.open(document.getElementById('o').innerHTML);}