我刚刚第一次制作表格。
我在访问该表单的值并将其存储到变量(稍后由函数使用)中时遇到问题。每当您提交表单时,它都会将您带到另一个网页。 JavaScript 文件附加到表单和另一个网页。
我尝试过的 - [如果我为属性提供 ID]
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>
编辑
我使用 .value 工作,我怎样才能让它登录这两个网页。
最佳答案
.val()
是用于输入值的 jQuery 方法。
尝试element.value
。
此外,xxx()
始终是一个函数,但元素内肯定没有可用的 value()
函数。
关于javascript - 基本表单 [Javascript/HTML],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32252246/