JQuery checks whether radio is selected and obtains the selected value.
A JQuery method is used to determine whether radio is selected and obtain the selected value. There is nothing special to mention. You can use it directly.
The Code is as follows: |
|
Other radio operations will be added later. Run the Code directly. <Html xmlns = "http://www.w3.org/1999/xhtml"> <Head> <Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/> <Title> JQuery radio </title> <Script type = "text/javascript" language = "javascript" src = "http://www.aimks.com/wp-includes/js/jquery/jquery.js"> </script> <Script type = "text/javascript" language = "javascript"> /* ------ Determine whether radio is selected and obtain the selected value --------*/ $ (Function (){ $ ("# BtnSubmit"). click (function (){ Var val = $ ('input: radio [name = "sex"]: checked'). val (); If (val = null ){ Alert ("Nothing selected! "); Return false; } Else { Alert (val ); } Var list = $ ('input: radio [name = "list"]: checked'). val (); If (list = null ){ Alert ("Please select one! "); Return false; } Else { Alert (list ); } }); }); </Script> </Head>
<Body> <Form id = "form1"> <Input type = "radio" name = "sex" value = "male"/> male <Input type = "radio" name = "sex" value = "female"/> female <Br/> <Input type = "radio" name = "list" value = "very satisfied"/> very satisfied <Input type = "radio" name = "list" value = "satisfied"/> satisfied <Input type = "radio" name = "list" value = "not satisfied"/> not satisfied <Input type = "radio" name = "list" value = "very poor"/> very poor <Br/> <Input type = "submit" value = "submit" id = "btnSubmit"/> </Form> </Body> </Html> |