The weui-switch control, how to set the value after the form is submitted, after the weui-switch is submitted

Source: Internet
Author: User

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>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.