基本表单[Javascript/HTML]
我第一次做了一张表格 我在访问该表单的值并将其存储到变量(稍后由函数使用)时遇到问题。无论何时提交表单,它都会将您带到另一个网页一个JavaScript文件同时附加到表单和另一个网页。 我所尝试的-[如果我为属性提供id]基本表单[Javascript/HTML],javascript,jquery,html,forms,Javascript,Jquery,Html,Forms,我第一次做了一张表格 我在访问该表单的值并将其存储到变量(稍后由函数使用)时遇到问题。无论何时提交表单,它都会将您带到另一个网页一个JavaScript文件同时附加到表单和另一个网页。 我所尝试的-[如果我为属性提供id] var someVariable = document.getElementById("Some id").val(); console.log(someVariable); // It shows a error in console, not the value
var someVariable = document.getElementById("Some id").val();
console.log(someVariable); // It shows a error in console, not the value.
再来一次
var someVariable = document.forms["Form Name"]["Property name"].value();
console.log(someVariable);
控制台中出现了一些错误
表格
<div id="ques">
<ul>
<form name="myForm" action="Answer.html" method="get">
<li>What cuisine?(You can leave it empty)<br>
<input list="Cuisines" class="normal" type="text" name="Cuisine" placeholder="Like Chinese" pattern="Chinese|North Indian|Italian|American">
<datalist id="Cuisines" autocomplete="off">
<option value="Chinese"></option>
<option value="North Indian"></option>
<option value="Italian"></option>
<option value="American"></option>
</datalist></li>
<li>On a scale of 1 to 10, how much hungry are you?<br><input class="normal" type="number" name="hunger" min="1" max="10" required></li>
<li><input class="special" type="checkbox" name="Personality" value="Vegetarian"checked> Vegetarian
<input class="special" type="checkbox" name="Personality" value="Non-Vegetarian" > Non-Vegetarian
</li>
<li>On a scale of 1 to 10, how much healthy do you want the food to be?<br><input class="normal" type="number" name="Calories" min="1" max="10" required></li>
<li>What will be the max cost of the food, per person?<br>(Quality of the food will be affected)<br><input class="normal" type="number" name="quality" placeholder=" Like 400" step="50" required></li>
<li>How many people?<br><input class="normal" type="number" name="Amount of people" required></li>
<li><a href="Answer.html"><input class="normal" type="submit"></a></li>
</form>
</ul>
</div>
- 什么菜?(你可以空着吃)
- 从1到10分,你饿了多少?
- 素食者
非素食者
- 在1到10的范围内,你希望食物健康多少?
- 人均食品的最高成本是多少?
(食品质量将受到影响)
- 有多少人?
编辑
我使用.value工作,如何让它登录两个网页。.val()
是一种用于输入值的jQuery方法
尝试元素。值
另外,xxx()
始终是一个函数,但元素中肯定没有可用的value()
函数。使用.value
而不是.value()
谢谢!但仍然不完整,它记录,但在表单网页上。我在两个网页上都使用了一个javascript文件。我应该创建另一个文件吗?如果重新加载的是一个完全独立的页面,脚本将重新加载,变量将重置。您需要找到一种方法,既不重新加载变量,也不通过查询字符串传递变量。尝试查看jQuery动态修改HTML,以便在重定向到下一页时保留变量或传递查询字符串。@bransonl.val()
是.value
的jQuery版本,而不是.value()
@jon kanter我建议使用.value
而不是.value()
他/她第二次尝试时尝试了.value()
。