如何在web表单中传递用户输入的数据并将其传递到Java脚本函数中

如何在web表单中传递用户输入的数据并将其传递到Java脚本函数中,java,javascript,html,forms,Java,Javascript,Html,Forms,我试图从这里获取输入的值: index.html <form name="ytenter" action="youtbe.html" method="get"> url: <input type="text" id="url"name="url"> stop <input type="text" id="stop" name="stop"> <input type="submit" value="Submit" onclick="ytstop(this.

我试图从这里获取输入的值: index.html

<form name="ytenter" action="youtbe.html" method="get">
url: <input type="text" id="url"name="url">
stop <input type="text" id="stop" name="stop">
<input type="submit" value="Submit" onclick="ytstop(this.stop)">
</form>

网址:
停止
并在id=url和id=stop中获取输入的值

并在此处将其运行到youtbe.html:

<head>

<script>
(function ytstop() {

var stopPlayAt=10; // Stop play at   time in seconds

var stopPlayTimer; // Reference to settimeout call

   // This code loads the IFrame Player API code asynchronously.
var tag = document.createElement("script");
tag.src = "//www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName("script")[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);

// This function creates an <iframe> (and YouTube player)
// after the API code downloads.
var player;
window.onYouTubeIframeAPIReady = function () {
    player = new YT.Player("player", {
        "height": "315",
            "width": "560",
            "videoId": "L6cVcbkx8l8",
            "events": {
            "onReady": onPlayerReady,
                "onStateChange": onPlayerStateChange
        }
    });
}

// The API will call this function when the video player is ready.
// This automatically starts the video playback when the player is loaded.
function onPlayerReady(event) {
    event.target.playVideo();
}

// The API calls this function when the player's state changes.
function onPlayerStateChange(event) {
    var time, rate, remainingTime;
    clearTimeout(stopPlayTimer);
    if (event.data == YT.PlayerState.PLAYING) {
        time = player.getCurrentTime();
        // Add .4 of a second to the time in case it's close to the current time
        // (The API kept returning ~9.7 when hitting play after stopping at 10s)
        if (time + .4 < stopPlayAt) {
            rate = player.getPlaybackRate();
            remainingTime = (stopPlayAt - time) / rate;
            stopPlayTimer = setTimeout(pauseVideo, remainingTime * 1000);
        }
    }
}

function pauseVideo() {
    player.pauseVideo();
}
})();

</script>







</head>

<body>

<div id="player">

</div>


</html>

(函数ytstop(){
var stopPlayAt=10;//以秒为单位停止播放
var stopPlayTimer;//对settimeout调用的引用
//此代码异步加载IFrame播放器API代码。
var tag=document.createElement(“脚本”);
tag.src=“//www.youtube.com/iframe_api”;
var firstScriptTag=document.getElementsByTagName(“脚本”)[0];
firstScriptTag.parentNode.insertBefore(标记,firstScriptTag);
//此函数用于创建(和YouTube播放器)
//API代码下载后。
var播放器;
window.onYouTubeIframeAPIReady=函数(){
player=新的YT.player(“player”{
“高度”:“315”,
“宽度”:“560”,
“videoId”:“L6cVcbkx8l8”,
“事件”:{
“onReady”:onPlayerReady,
“onStateChange”:onPlayerStateChange
}
});
}
//当视频播放器准备就绪时,API将调用此函数。
//这会在加载播放器时自动启动视频播放。
函数onPlayerReady(事件){
event.target.playVideo();
}
//当播放器的状态改变时,API调用此函数。
函数onPlayerStateChange(事件){
风险值时间、比率、剩余时间;
clearTimeout(stopPlayTimer);
if(event.data==YT.PlayerState.PLAYING){
time=player.getCurrentTime();
//在时间上加上0.4秒,以防接近当前时间
//(在10秒停止后,当达到播放时,API不断返回~9.7)
如果(时间+4<停止播放){
rate=player.getPlaybackRate();
剩余时间=(停止播放时间)/速率;
StopLayTimer=setTimeout(pauseVideo,剩余时间*1000);
}
}
}
函数pauseVideo(){
player.pauseVideo();
}
})();
我需要从表单中获取“stop”,并将其放入顶部的stopPlayAt VAR中

然后我需要从表单中输入“url”并将其放入“videoID”:


谢谢你的帮助。只希望最终产品允许输入youtube链接和时间,并运行它,直到以秒为单位输入该时间。

我想让您参考本页的顶部答案:

这使您能够在URL中获取get参数的值