【问题标题】:How can I make a input that goes to a youtube video?如何进行进入 youtube 视频的输入?
【发布时间】:2020-08-10 18:46:29
【问题描述】:

我正在尝试通过输入视频 ID 来输入到 youtube 视频。这段代码我做错了什么?

<form method="get" action="http://www.youtube.com/embed/">
            <input id="searchinput" type="text" placeholder="Enter Video ID" name="" value="">
            <input type="hidden">
</form>

【问题讨论】:

  • 您是否使用任何 javascript 代码来“获取”用户输入的文本?

标签: html forms input youtube


【解决方案1】:

您不必使用这样的表格。 您可以使用 javascript 从输入中获取值并更改页面。

<head>
     <script>
        function goToYoutube(){
            const id = document.querySelector("#searchinput").value;
            location.href = "http://www.youtube.com/embed/" + id;
        }
    </script>
</head>
<body>
    <input id="searchinput" type="text" placeholder="Enter Video ID" name="" value="">
    <button type="button" onclick="goToYoutube()">GO</button>
</body>

我不知道该链接是否正确,但代码有效!

【讨论】:

    猜你喜欢
    • 2014-10-16
    • 1970-01-01
    • 2018-03-10
    • 2016-10-15
    • 1970-01-01
    • 1970-01-01
    • 2016-04-17
    • 2023-03-06
    • 1970-01-01
    相关资源
    最近更新 更多