【问题标题】:How to reset a form using: input type=reset如何使用以下方法重置表单:input type=reset
【发布时间】:2017-03-25 23:42:48
【问题描述】:

您好,这是我在这里的第一个问题,如果我弄错了,请原谅我。

我正在尝试使用 HTML5 中的 input type=reset 标记重置表单,但遇到了问题。我将输入我的代码的一部分,我要问的问题是: 表格是否在单独的 div 中是否重要?我将使用 Javascript,所以如果你能告诉我一个简单的 JS 方法会很棒,但不是 jQuery。你能提供的任何帮助都会很棒!

这一切都在一个 feildset 中。

<div id="formset">
  <label for="textfield" class="form">First Name:</label>
  <input type="text" name="textfield" id="textfield" class="input">




 <p></p>
  <label for="textfield2">Last Name:</label>
  <input type="text" name="textfield2" id="textfield2" class="input">



<p></p>
  <label for="email"></label>
  <input type="email" name="email" id="email" class="input">
  <p></p>
    <label for="date"></label>


<input type="date" name="date" id="date" class="input"></div> <input type="reset" value="Reset">

【问题讨论】:

  • 需要一个 &lt;form&gt; 标签才能重置工作,里面的 div 没有差异。
  • 谢谢@dandavis

标签: javascript html forms input reset


【解决方案1】:
I think you need to use form tag. Here is my code:

<form action="" method="">
        <div id="formset">
            <label for="textfield" class="form">First Name:</label>
            <input type="text" name="textfield" id="textfield" class="input">

            <p></p>
            <label for="textfield2">Last Name:</label>
            <input type="text" name="textfield2" id="textfield2" class="input">

            <p></p>
            <label for="email"></label>
            <input type="email" name="email" id="email" class="input">
            <p></p>
            <label for="date"></label>

            <input type="date" name="date" id="date" class="input">
        </div> 

        <input type="reset" value="Reset">
    </form> 

【讨论】:

  • 谢谢。我不敢相信我搞砸了。再次感谢您,您确实提供了帮助。
【解决方案2】:

没有表单标签,表单不能声明为表单。当您使用表单标签时,您可以使用所有表单事件,例如提交、重置等。像这样

<form action="" method="">
  your inputs.....
</form>

【讨论】:

    猜你喜欢
    • 2013-05-03
    • 1970-01-01
    • 1970-01-01
    • 2013-12-31
    • 1970-01-01
    • 1970-01-01
    • 2016-04-15
    • 2012-03-30
    相关资源
    最近更新 更多