如何打印出输入文本的值?Javascript和HTML



现在,这是我的代码。我想做的是将#替换为与输入文本的值相对应的值
所以不是像";上推#时间/#秒";,我想要像";上推40次/3秒";。
我的URL更改为值

settings.html?pushupQuantity=30&pushupTime=2&pullupQuantity=40&pullupTime=4

我不太擅长HTML和JavaScript,也不知道该怎么做。

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<div class="jumbotron text text-center">
<h1>Settings</h1>
</div>
<div class="container justify-content-center">
<h2>Pushup # time / # seconds</h2>
<h2>Pullup # time / # seconds</h2>
<h2>Squats # time / # seconds</h2>
<form action='./settings.html'>
<h1>Pushups</h1>
<img src="https://media.tenor.com/images/28fecfea6b4a7c36c7e45c76fe86b3b8/tenor.gif" alt="pushup gif" /><br>
<label for="pushupQuantity">Pushup Quantity: </label>
<input type="text" id="pushupQuantity" name="pushupQuantity" value="30"><br>
<label for="pushupTime">Seconds in between: </label>
<input type="text" id="pushupTime" name="pushupTime" value="2"><br>
<hr>
<h1>Pullups</h1>
<img src="https://thumbs.gfycat.com/FailingSlushyBoa-size_restricted.gif" alt="pullup gif" /><br>
<label for="pullupQuantity">Pullup Quantity: </label>
<input type="text" id="pullupQuantity" name="pullupQuantity" value="40"><br>
<label for="pullupTime">Seconds in between: </label>
<input type="text" id="pullupTime" name="pullupTime" value="4"><br>
<hr>
<input class="btn btn-primary" type="submit" value="Submit">
</form>
</div>

首先,您需要为每个活动创建函数,该函数将在特定的活动面板上调用并更新。只需通过识别输出字段将这些值更新到您的页面中

PushUp活动的更新代码。`

function calculatePushup(){
document.getElementById("pushupQuantityLabel").innerHTML = document.getElementById("pushupQuantity").value;
document.getElementById("pushupTimeLabel").innerHTML = document.getElementById("pushupTime").value;
}
// update with default values when page load for the first time.
calculatePushup();
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Settings</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<script>

</script>
</head>
<body>
<div class="jumbotron text text-center">
<h1>Settings</h1>
</div>
<div class="container justify-content-center">

<h2>Pushup <span id="pushupQuantityLabel">#</span> time / <span id="pushupTimeLabel">#</span> seconds</h2>
<h2>Pullup # time / # seconds</h2>
<h2>Squats # time / # seconds</h2>
<form action='./settings.html'>
<h1>Pushups</h1>
<img src="https://media.tenor.com/images/28fecfea6b4a7c36c7e45c76fe86b3b8/tenor.gif" alt="pushup gif" /><br>
<label for="pushupQuantity">Pushup Quantity: </label>
<input type="text" id="pushupQuantity" name="pushupQuantity" value="30" onkeyup="calculatePushup()"/><br>
<label for="pushupTime">Seconds in between: </label>
<input type="text" id="pushupTime" name="pushupTime" value="2"  onkeyup="calculatePushup()"/><br>
<hr>
<h1>Pullups</h1>
<img src="https://thumbs.gfycat.com/FailingSlushyBoa-size_restricted.gif" alt="pullup gif" /><br>
<label for="pullupQuantity">Pullup Quantity: </label>
<input type="text" id="pullupQuantity" name="pullupQuantity" value="40"><br>
<label for="pullupTime">Seconds in between: </label>
<input type="text" id="pullupTime" name="pullupTime" value="4"><br>
<hr>
<input class="btn btn-primary"type="submit" value="Submit">
</form>
</div>
</body>
</html>

以同样的方式,您可以为其他活动添加功能。只需将事件添加到要调用函数的字段中。创建一个函数,该函数将获取字段值,然后通过标识它们各自的id将它们显示到输出字段中。

最新更新