如何从输入更改src?

时间:2019-02-20 10:36:53

标签: javascript html css

如何使用javascript从输入中更改src值?

<input class="url" id="url1" type="url" value="youtube url">
<input onclick="changevideo()" class="add-video" id="add-video1" type="submit" value="add to playlist">

<iframe class="video" id="video1" ></iframe>

<script>
    function changevideo() {
        var ddd = document.getElementById('url').value;
        document.getElementById('video1').setAttribute('src', ddd);
    }
</script>

2 个答案:

答案 0 :(得分:1)

您可以像这样使用它

function changevideo() {
var e=document.querySelector('#url1').value;
console.log(e)
  document.getElementById('video1').setAttribute('src', e)
  }
<input class="url" id="url1" type="url" value="youtube url">
<input onclick="changevideo()" class="add-video" id="add-video1" type="submit" value="add to playlist">
<iframe class="video" id="video1"></iframe>

答案 1 :(得分:0)

选择视频时,您应该可以访问src属性:     let video = document.getElementById('video1'); video.src = path;