gpt4 book ai didi

javascript - 为什么我的输入框显示未定义?

转载 作者:行者123 更新时间:2023-11-28 17:49:46 25 4
gpt4 key购买 nike

当我单击调用 showDetails() 函数的提交按钮时,nameemail 输入框显示未定义。当输入框中有值时也会发生这种情况:

<script type="text/javascript">
function showDetails(){

var e = document.getElementById("email");
//var t = document.getElementById("t");
var n = document.getElementById("name");
var m = document.getElementById("m");

var c;
var r;
document.getElementById("email").value = c;
document.getElementById("name").value = r;
document.getElementById("t").value = "Your name is: "+r+" and your email is: "+c;
}
</script>

为什么会发生这种情况?

最佳答案

我相信这是因为您将值分配给了未定义。

<script type="text/javascript">
function showDetails() {

var e = document.getElementById("email");
//var t = document.getElementById("t");
var n = document.getElementById("name");
var m = document.getElementById("m");

var c = document.getElementById("email").value; // Here you set it the value = undefined variable
var r = document.getElementById("name").value;

document.getElementById("t").value = "Your name is: " + r + " and your email is: " + c;
}
</script>

关于javascript - 为什么我的输入框显示未定义?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45819534/

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