gpt4 book ai didi

javascript - 使用通过 ID 获取元素进行用户输入

转载 作者:行者123 更新时间:2023-12-03 07:28:59 24 4
gpt4 key购买 nike

我正在尝试编写这个网络应用程序,让用户输入有关其设备的重要信息,然后将其放置在 JavaScript 中的相关位置。这是到目前为止我的代码。

<script type="text/javascript">
function update() {
var key = document.getElementById("key").value;
if (input.length < 40) {
alert("Please enter a valid input");
return;
}
document.getElementById("access key").innerHTML;
}
</script>
<script type="text/javascript">
function update() {
var device_id = document.getElementById("device_id").value;
if (input.length < 24) {
alert("please enter a valit input");
return;
}
document.getElementById("device_id").innerHTML;
}

</script>
<p><input type="text" id="key" autofocus placeholder = "Enter product key here" /></p>
<p><input type="text" id="device_id" autofocus placeholder = "Enter device ID here" /></p>
<p><input type="submit" value="Submit" onclick="update()"/></p>


<h1>Rotary Gate Systems</h1>



<article>
<a href="#" class="button open_button">Open</a>
</article>
<article>
<a href="#" class="button close_button">Close</a>
</article>

<article>
<p class="status_closed status_button">CLOSED</p>
<p class="status_open status_button">OPEN</p>
<p class="status_none status_button">NO CONNECTION</p>
</article>



<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.js'></script>
<script>/*jslint browser: true*/
/*global $, jQuery*/
/*jshint strict: true */

/*EDIT THESE VARIABLES*/
//key is the same as your 'access token'
var key = "key"

//device_id is the same as the 'core id'
var device_id = "device_id"

我认为我可能在提交按钮中遗漏了某些内容,或者我尝试使用此属性执行的操作可能无法实现。有人可以看一下这个并让我知道我可能在哪里搞砸了吗?

最佳答案

您需要将条件语句更改为,

if (key.length < 40) {

if (device_id.length < 40) {

因为 input 未在您的 update() 函数中定义。

此外,您应该考虑将两个 update() 函数合并为一个,以便对 keydevice_id 进行有效性检查每当提交表单时都在一起。

关于javascript - 使用通过 ID 获取元素进行用户输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35877932/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com