0

我正在使用 Django 和 Bootstrap,我有一个页面,其中有两个输入和一个提交按钮:

   <div class="col-lg-5">
         <form id="search_form" align="right" action="/comparison/" class="form-inline" method ="get" role="form">
       <input id="navPersonSearch" class="input form-control" type="text" name="q1"
        placeholder="Search for Actor/Actress"
             autocomplete="off" >

  </div> <!-- /.col -->
    <div class="col-lg-2">
    <button type="submit" class="btn btn-primary btn-lg btn-block">Compare</button>
   </div> <!-- ./col -->
   <div class="col-lg-5">
       <input id="navPersonSearch2" class="input form-control" type="text" name="q2"
        placeholder="Search for Actor/Actress"
             autocomplete="off" >
  </form> 
  </div> <!-- /.col -->

但是,当您提交表单时,只会提交第一个值。例如,在第一个输入中,如果您有“Tom”,而第二个输入中有“Bob”,它将重定向到:

http://127.0.0.1:8000/comparison/?q2=Bob

当我想要提交两个值时。

4

2 回答 2

1

HTML 无效。移动<form>标签以完全包含开头和结尾<div>的 s。像这样:

<form id="search_form" align="right" action="/comparison/" class="form-inline" method ="get" role="form">  
    <div class="col-lg-5">  
        <input id="navPersonSearch" class="input form-control" type="text" name="q1"
               placeholder="Search for Actor/Actress" autocomplete="off" >
    </div> <!-- /.col -->
    <div class="col-lg-2">
        <button type="submit" class="btn btn-primary btn-lg btn-block">Compare</button>
     </div> <!-- ./col -->
     <div class="col-lg-5">
         <input id="navPersonSearch2" class="input form-control" type="text" name="q2"
                placeholder="Search for Actor/Actress" autocomplete="off" >
     </div> <!-- /.col -->
 </form> 
于 2013-10-25T23:47:04.910 回答
1

做类似的事情

<p><strong></p></strong>

是不好的,并导致 html 代码的解释错误,你应该提前移动标签

<form id="search_form" align="right" action="/comparison/" class="form-inline" method ="get" role="form">
   <div class="col-lg-5">
       <input id="navPersonSearch" class="input form-control" type="text" name="q1"
        placeholder="Search for Actor/Actress"
             autocomplete="off" >
   </div> <!-- /.col -->
   <div class="col-lg-2">
      <button type="submit" class="btn btn-primary btn-lg btn-block">Compare</button>
   </div> <!-- ./col -->
   <div class="col-lg-5">
       <input id="navPersonSearch2" class="input form-control" type="text" name="q2"
        placeholder="Search for Actor/Actress"
             autocomplete="off" >
    </div> <!-- /.col -->
  </form> 
于 2013-10-25T23:48:02.733 回答