【发布时间】:2018-06-26 17:59:48
【问题描述】:
有谁知道如何解决以下问题:我希望用户输入的表单在不同的 HTML 文件中得到警告。
这是我到目前为止写的。它适用于名为'name'的id,但我不知道为什么它不适用于'position'。
“index.html”文件:
<script>
function myFunction() {
name = document.getElementById("name").value;
position = document.getElementById("position").value;
window.location.replace("signature.html");
return false;
}
</script>
<form class="formulario" onsubmit="return myFunction()">
Name: <input type="text" name="name" id="name"><br>
Position: <input type="text" name="position" id="position"><br>
<br>
<input type="submit" value="Generate Signature">
</form>
“signature.html”文件 - 注意警报(名称)和警报(位置)=>警报(名称)有效,但警报(位置)无效。我想了解如何解决这个问题。
<html>
<head>
</head>
<body>
<div class="signature_general">
<div class = "signature_middle">
<div id = "signature_details">
<font size="2px">Regards,</font><br>
<b><font color="#808080" size="3px" id="nameInput">Francisco Jurado</font></b><br>
<font size="2px" id="posInput">Accounting Systems Team Leader</font>
</div>
</div>
</div>
<script>
alert(name);
alert(position);
</script>
</body>
</html>
非常感谢
编辑:我注意到我收到一个错误,其中“位置”是“未定义”。有谁知道吗?
【问题讨论】:
-
显然,您还没有标记“名称”和“位置”的变量。试试这个: var name='test1', position='test2';警报(名称);警报(位置);
-
@Sphinx 编辑:你的意思是在“signature.html”文件中吗?
-
@Sphinx 我尝试了以下方法(可能不是你的意思):在“index.html”文件中声明,如下:var name = document.getElementById("name").value ; var position = document.getElementById("position").value;
标签: javascript alerts