2015-11-14 18 views
1

我有一個搜索欄,我試圖攔截POST,追加「標籤:」,然後提交它,所以如果有人在搜索欄中輸入「apple」,它會出現標籤:蘋果提交HTML文章特定值

<form method="get" action="/search" id="search-home"> 
      <button type="submit" value="search"></button> 
      <input type="hidden" name="type" value="product" /> 
      <input type="text" name="q" placeholder="Search" /> 
     </form> 
+0

您可以在這裏您將使用'apple' – void

+0

你是什麼意思去做呢? –

+0

你可以嘗試使用jQuery嗎? – vel

回答

0
 <!doctype html> 
     <html lang="en"> 
     <head> 
     <meta charset="UTF-8"> 
     <meta name="Generator" content="EditPlus®"> 
     <meta name="Author" content=""> 
     <meta name="Keywords" content=""> 
     <meta name="Description" content=""> 
     <title>Document</title> 
     <script src="//code.jquery.com/jquery-1.11.3.min.js"></script> 
     <script src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script> 
     </head> 
     <body> 

      <form method="get" action="/search" id="search-home"> 
       <button type="submit" value="search">submit</button> 
       <input type="hidden" name="type" value="product" /> 
       <input type="text" name="q" placeholder="Search" class="searchtext"/> 
      </form> 

     <script> 
     $(document).on('submit','#search-home',function(){ 
     var searchtext = $('.searchtext').val(); 
     $('.searchtext').val("tag:"+searchtext); 
     }); 
     </script> 

     </body> 
     </html>