Home > Web Front-end > JS Tutorial > About serialize serialization and sign processing example code

About serialize serialization and sign processing example code

零下一度
Release: 2017-06-28 14:46:11
Original
1333 people have browsed it

Talk less and do more, run the code directly, there are comments in the code:

  <!DOCTYPE html> 2 
  <html lang="zh"> 3 <head> 4     
  <meta charset="UTF-8" /> 5     
  <meta http-equiv="X-UA-Compatible" content="ie=edge" /> 6     
  <title>serialize 序列化 +号处理</title> 7 </head> 8 <body> 9     
  <form id="form">10         <label>11             
  <input type="checkbox" name="r1" id="r1" value="前端工程师  厉害!" />前端工程师12         
  </label>13         <label>14             
  <input type="checkbox" name="r1" id="r1" value="测试工程师  厉害!" />测试工程师15         
  </label>16         <label>17             
  <input type="checkbox" name="r1" id="r1" value="后端工程师  厉害!" />后端工程师18         
  </label>19         
  <input type="button" name="btn" id="btn" value="提交" />20     </form>21     
  <script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js?1.1.11"></script>22     
  <script type="text/javascript">23         $(function(){24             
  $('#btn').click(function(){25                 
  //serialize序列化,默认会调用encodeURIComponent()进行编码26                 
  var pre = $('#form').serialize()27                 
  //r1=%E5%89%8D%E7%AB%AF%E5%B7%A5%E7%A8%8B%E5%B8%88++%E5%8E%89%E5%AE%B3%EF%BC%8128                 
  //注意有+号29                 console.log(pre);30                 
  //对整个字符串中符合条件的+号都进行替换31                 
  var next = pre.replace(/\+/g," ");32                 
  //对serialize后的内容进行解码33                 
  next = decodeURIComponent(next);34                 
  //r1=前端工程师  厉害!35                 
  //注意没有+号了36                 
  console.log(next)37             });38         });39     
  </script>40 
  </body>41 
  </html>
Copy after login

The above is the detailed content of About serialize serialization and sign processing example code. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template