<HTML> <Head> <MetaCharSet= "Utf-8"> <Scriptsrc= "Http://oa.feeyo.com/js/jquery-1.4.2.min.js"type= "Text/javascript"></Script> </Head> <Body> <DivID= ' xxx '> <inputtype= "checkbox"value= "Orange"ID= ' Id2 'name= "Check">Orange 1</input> <inputtype= "checkbox"value= "Banana"ID= ' ID3 'name= "Check">Banana 1</input> <inputtype= "checkbox"value= "Watermelon"ID= ' Id4 'name= "Check">Watermelon 1</input> <inputtype= "checkbox"value= "Mango"ID= ' ID5 'name= "Check">Mango 1</input> <inputtype= "checkbox"value= "Grape"ID= ' Id6 'name= "Check">Grape 1</input> <inputtype= "button"value= "Get"ID= "B1"> </Div> </Body> <Script> //Method 1 $("#b1"). Click (function(){ varData_arr=[]; //defines an empty array to hold the array JSON //Gets the marquee check box #xxx自己改 because it is a multiple box result is an array if it is a radio box or an input box is not an array varCheck_arr= $('#xxx input[type=checkbox]:checked'); alert (check_arr.length); //popped to see a few //and then loop him .$.each (Check_arr,function(){ //I want to add an element to the array.Data_arr.push ({id:$ ( This). attr ('ID'), value:$ ( This). Val ()}); }); Console.log (Data_arr); }); </Script></HTML>
Put the checkbox selected loop into the array