我想在单击按钮后更改iframe的src。我找不到解决方案

     <iframe id="Pencere" name="window" src="https://stackoverflow.com/" ></iframe>
     <input id="number" name="Number" type="text" >
     <input id="button" class="button button1" type="button" value=" Jump " onclick="javascript:jump()"/>

     <script type="text/javascript">
     function jump()
      {
        var number= document.getElementById("number").value;
        var url = "https://www.otherwebsite.com/"+number+"/1";
        document.getElementById("Pencere").src = url;
      }
</script>


单击按钮后的结果:javascript - 单击按钮即可更改iframe src-LMLPHP

最佳答案

function newSrc() {
  var e = document.getElementById("MySelectMenu");
  var newSrc = e.options[e.selectedIndex].value;
  document.getElementById("MyFrame").src=newSrc;
}

<iframe src="https://beamtic.com/" style="width:450px;height:450px;overflow:scroll;" id="MyFrame"></iframe>
<select id="MySelectMenu">
  <option value="https://beamtic.com/">Beamtic</option>
  <option value="https://fr.wikipedia.org/wiki/Main_Page">Wiki</option>
</select>
<button onClick="newSrc();">Change Iframe Src</button>





希望您正在寻找这种功能

关于javascript - 单击按钮即可更改iframe src,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/59176484/

10-13 04:21