如何使用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>
答案 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;