Blogger Information
Blog 100
fans 8
comment 2
visits 150598
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
input标签type="checkbox"时,选中/不选分别传值true/false
lilove的博客
Original
3102 people have browsed it

input复选框的传值

  • 通常我们使用input标签时这样写:

<input type="checkbox" name="save" id="save" value="true">

  • 那么js获取值时,如果不将复选框打勾,则服务端接口获取不到 save 的值:

  • php服务接口获取的 $_POST 中没有 $_POST['save'] 的值。

  • 要设置复选框的默认值与选中之后的值可以将 checkbox 写成下面这样:

<input type="hidden" name="save" value="false">

<input type="checkbox" name="save" id="save" value="true">

  • 不选时传值:false

  • 选中时传值:true

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post