<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd> <Html xmlns = "http://www.w3.org/1999/xhtml"> <Head> <Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/> <Title> </title> <Script src = "jquery-1.6.2.min.js" type = "text/javascript"> </script> <Script type = "text/javascript"> $ (Function (){ $ ("Input [name = 'love']"). click (function (){ // Obtain all the check boxes with the name "love" Var $ Checks = $ ("input [name = 'love']: checked "); Var arr = new Array (); // Use the element's each method // Loop the dom array in the Jquery object $ Checks. each (function (index, value ){ // Alert (value ); Arr [index] = value. value; }); $ ("# MessageInfo"). text ("You selected" + arr. length + "hobbies," + arr. join (",")); }); }); </Script> </Head> <Body> <Input type = "checkbox" name = "love" value = "FootBall"/> FootBall <Input type = "checkbox" name = "love" value = "BasketBall"/> BasketBall <Input type = "checkbox" name = "love" value = "VallyBall"/> volleyball <P id = "MessageInfo"> </p> </Body> </Html> |