js获取form的值提交


 form体使用summit按钮提交会自动发送form里的input等参数。


 我们使用js进行form体提交时  除了逐个获取input的值外  还可以使用如下方法:

jsp页面:

  <form class="form-inline col-sm-11" id="search_form">
  <div class="form-group">名称</label>
    <input type="text" class="form-control" name="name" id="search_name" placeholder="中文或英文名称模糊匹配" />
  </div>
  <div class="form-group">
    <select class="form-control" name="confidence" id="search_confidence">
      <option value="">- 星级筛选 -</option>
      <option value="1">1</option>
      <option value="2">2</option>
      <option value="3">3</option>
      <option value="4">4</option>
      <option value="5">5</option>
    </select>
  </div>
  <div class="form-group">
    <select class="form-control" name="hidden" id="search_name">
      <option value="">- 全 部 -</option>
      <option value="0" selected="selected">显示</option>
      <option value="1">隐藏</option>
    </select>
  </div>
   <div class="form-group">
    <select class="form-control" name="version" id="search_version">
      <option value="">- 全 部 -</option>
      <option value="1" selected="selected" >v1</option>
      <option value="2">v2</option>
    </select>
  </div>
  <button type="submit" class="btn btn-default query">查询</button>
  <button type="button" class="btn btn-default add">添加</button>
  <button type="button" class="btn btn-default export">导出</button>
</form>



js提交方法:

  
 var $searchForm = $('#search_form');
  $searchForm.on('click', 'button.add', function(){
            $formMoal.formSet({});
            $formMoal.modal('show');
        }).on('submit',function(){
        	$dt.DataTable().searchEx( {} ).draw();
        	return false;
        }).on('click', 'button.export', function(){ 
        var searchData={};
        searchData.search=$('#search_form').formGet();            
        post('/export/list',searchData);        	
        });
              
              
      function post(URL, PARAMS) {        
        var temp = document.createElement("form");        
        temp.action = URL;        
        temp.method = "post";        
        temp.style.display = "none";        
        for (var x in PARAMS.search) {        
           var opt = document.createElement("textarea"); 
           if(x=="name"||x=="confidence"||x=="hidden"||x=="version"){      
             opt.name = x;        
             opt.value = PARAMS.search[x];
             temp.appendChild(opt);  
           }       
        }        
        document.body.appendChild(temp);        
        temp.submit(); 
      }  



你可能感兴趣的:(JavaScript,jsp,form,提交,取值)