我正在尝试使我的网站在表单上有一个文本框和一个提交按钮。当用户在文本框中输入视频的 URL 并单击提交时,JavaScript 应该用该 URL 替换特定的文本块。
这是我的代码。我是 JavaScript 新手,提前感谢您的帮助!:
<!doctype html>
<html>
<head>
<meta type="utf-8">
<title> Vid_hack </title>
</head>
<style type="text/css">
a:link { color: #CC0000 ; text-decoration: bold}
a:active { color: #CC0000 ; text-decoration: none}
a:visited { color: #CC0000; text-decoration: none}
a:hover { color: #FFFFFF; text-decoration: bold; background: #336699}
body {
background-color: #222222;
}
</style>
<body>
<div align="center">
<p center="" style="background: #444444; border-radius: 15px; border: solid 3.0pt white; padding: 10px">
<object><param name="allowfullscreen" value="true"></param><p id="url"><embed src="INSERT-VIDEO-URL-HERE" type="application/x-shockwave-flash" allowfullscreen="1" width="800" height="600"></embed></p></object>
<BR>
<BR>
<form method="post">
<input type="text" name="vid" value="Insert URL here" maxlength="200" />
<br>
<button onclick="return vid()">Play</button>
</form>
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.3.js"></script>
<script>
function vid()
{
var txt = $("#vid").attr("value");
$("#url embed").attr("src",txt);
return false;
}
</script>
<BR>
<BR>
<BR>
<span style="color: #FFF" align="center">
<BR>
<BR>
Please view the included README file for more information.
</span>
</p>
</div>
<BR>
<BR>
<BR>
</body>
</html>