Background return data echo, use JS control default check box and drop-down box

Source: Internet
Author: User

<! DOCTYPE html><Htmllang="ZH-CN" ><Head><Metacharset="UTF-8" ><Title> Test</Title><?php $chk =Array' Ch1 ',' CH3 ',' Ch5 ');Get an array of checkbox-checked IDs in the background $slt =' Iph ';Background gets the value of select option?><ScriptType="Text/javascript"Src="//upcdn.b0.upaiyun.com/libs/jquery/jquery-1.8.3.min.js" ></Script><ScriptType="Text/javascript" >$(function(){var chkdata = <?php echo json_encode ($CHK);? >;var sltdata =' <?php echo $slt;? > '; $('. Chk '). each (function(){var self = $ (this);var Selfid = self.attr (' id '); $.each (Chkdata,function(N, v) {if (v = = Selfid) self.attr (' Checked ',' true '); }); }); $(' #select option '). each (function(){var self = $ (this);var selfval = Self.val ();if (Selfval = = Sltdata) self.attr (' Selected ',' true '); });});</Script></Head><Body><P><InputId="Ch1"class="Chk"Type="checkbox"Value="111" >111</P><P><InputId="CH2"class="Chk"Type="checkbox"Value="222" >222</P><P><InputId="CH3"class="Chk"Type="checkbox"Value="333" >333</P><P><InputId="CH4"class="Chk"Type="checkbox"Value="444" >444</P><P><InputId="Ch5"class="Chk"Type="checkbox"Value="555" >555</P><Divclass="Selectaera" ><SelectId="Select" ><OptionValue="SMT" > Hammer</Option><option value=  "iph" > Apple </option> <option value= "XM" > Xiaomi </option> < option value= "Nka" > Nokia </option> </select > </div></ body></HTML>    

Return data back in the background, use the JS control to select the check box and drop-down box by default

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.