我想创建一个带有文本输入元素的网页,我可以在其中放置网址并按下按钮以开始播放该网址中的视频。换句话说,我想让输入中的url成为视频标记的来源。
<!DOCTYPE html>
<html>
<head>
<script>
function write(){
document.write(document.getElementById('url').value);
}
</script>
</head>
<body>
<p>Enter the source of the video.</p>
<form id="frm1">
URL: <input id="url" type="text" name="fname"><br>
<input type="button" onclick="write()" value="Please Write the URL">
</form>
</body>
</html>
答案 0 :(得分:-2)
试试此代码
<!DOCTYPE html>
<html>
<head></head>
<body>
<p>Enter the source of the video.</p>
<form id="frm1">
URL: <input id="url" type="text" name="fname"><br>
<input type="button" onclick="write()" value="Please Write the URL">
</form>
<video id="myVideo" controls>
<source src="foo.ogg" type="video/ogg; codecs=dirac, speex">
Your browser does not support the <code>video</code> element.
</video>
<script>
function write()
{
var vid = document.getElementById('myVideo');
vid.src = document.getElementById('url').value;
vid.play();
}
</script>
</body>
</html>