javascript - 基本表单 [Javascript/HTML]

标签 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.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/

相关文章:

javascript - 如何计算 localStorage 中的特定 ID?

javascript - 从数组 Javascript 中拼接对象

javascript - 如何访问一个非全局函数并且它存在于另一个js文件中?

javascript - 在 kendo.ui.GridColumn 中格式化日期和 boolean 值

javascript - 难道不能在 Rails 中使用 jQuery 更改 CSS 属性吗?

jquery - HTML 图像未在 chrome 中显示,并且 jQuery 更改在 IE 中不起作用

javascript - D3 : enter(), 鼠标悬停/鼠标悬停时 exit()

javascript - 为什么 $.each 使数组对象未定义,但 for 循环有效

javascript - 将 innerText/textContent 与变量内的值进行比较

javascript - 我可以在对象类的更改上触发或执行 JavaScript 函数吗?