The weui-switch control, how to set the value after the form is submitted, after the weui-switch is submitted
I recently studied the weui framework and made some small experiments. I found that the weui-switch control could not directly submit and could not obtain the form information. In segmentfault, I found someone raised this issue, some people say that they can set an implicit label to capture the status of the switch. After trying it out, it is true. Write down my own solution as follows:
The switch control weui can only display the switch status and cannot submit data. I created a hidden radio tag based on my ideas, then, set the value attribute of the radio tag through this toggle control, and submit the tag so that php in the background can obtain the correct form information:
<! -- Implicit element, used to receive the button status. It must be set to checked for submission to be valid, otherwise, the submitted information cannot be obtained by php --> <input hidden = "hidden" id = "btn" name = "btn1" type = "radio" value = "off" checked =" checked "/> <div class =" weui-cells weui-cells_form "> <div class =" weui-cell weui-cell_switch "> <div class =" weui-cell _ bd "> Switch 1 </div> <div class = "weui-cell _ ft"> <input class = "weui-switch" type = "checkbox" id = "button1" name =" button1 "/> </div> <script> $ (function () {$ ("# button1 "). bind ("click", function () {// console. log ($ ("# button1 "). val (); if ($ ("# btn "). val () = "off") {$ ("# btn "). val ("on"); console. log ("Switch 1 Current status:" + $ ("# btn "). val ();} else {$ ("# btn "). val ("off"); console. log ("Switch 1 Current status:" + $ ("# btn "). val () ;}}) ;}); </script>