【问题标题】:Form Code Missing Something?表单代码缺少什么?
【发布时间】:2014-10-19 11:40:28
【问题描述】:

第一次在 Stackoverflow 上发帖,你们能告诉我这段代码缺少什么吗?它应该是一个表单,但“提交”按钮什么也不做。谢谢!

  <div class="container">
   <span class="reg"> <h1>Register Now</h1> </span>
    <div class="row">
      <div class="conent-part">
       <div class="form-body">
        <div class="fome-body">
          <form>
            <div class="row">
                <div class="form-part">
                    <div class="form-group">
                        <input type="email" class="form-control" id="exampleInputEmail1" placeholder="Your Name">
                    </div>
                    <div class="form-group">
                        <input type="email" class="form-control" id="exampleInputEmail1" placeholder="Your Email Address">
                    </div>
                    <div class="form-group">
                        <input type="email" class="form-control" id="exampleInputEmail1" placeholder="Nominee's Name">
                    </div>
                    <div class="form-group">
                        <input type="email" class="form-control" id="exampleInputEmail1" placeholder="Nominee's Email">
                    </div>
                </div>
                <div class="form-part">
                    <div class="form-group">
                        <input type="email" class="form-control" id="exampleInputEmail1" placeholder="Nominee's Sport">
                    </div>
                    <div class="form-group">
                        <textarea class="form-control" rows="3" placeholder="Accomplishments"></textarea>
                    </div>
                </div>

            </div>
            <div class="custom_btn">
                    <button type="button" class="btn btn-primary btn2">Submit</button>
                </div>
          </form>

【问题讨论】:

  • 您的开头&lt;form&gt; 标签没有任何属性。表单什么也不做,因为你还没有告诉它要做什么。
  • 同样修复你的 HTML,你的 5 个元素有相同的 id。
  • 我很难过,哈哈。我的大脑有点痛。

标签: html forms


【解决方案1】:

改变

<div class="custom_btn">
                <button type="button" class="btn btn-primary btn2">Submit</button>
</div>

<div class="custom_btn">
                <button type="submit" class="btn btn-primary btn2">Submit</button>
</div>

只需键入 type=button,您只是告诉我们它是一个按钮,而没有说明它的功能。type="submit" 将自动将表单提交到指定的 URL。

【讨论】:

  • 如果可以的话,我会投票给你们两个,但不幸的是我不能,因为我是新人。
【解决方案2】:
<button type="button"> 

没有默认行为,如果您想提交表单,您只需使用&lt;button&gt; 而不定义type 属性(submit 是默认值)。

See the docs for more info.

【讨论】:

  • 我明白了,我去看看。谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-05-04
  • 2013-07-01
  • 2018-11-13
  • 1970-01-01
  • 1970-01-01
  • 2010-11-04
  • 1970-01-01
相关资源
最近更新 更多