Jquery learn and practice 1-use ul Li to implement the single answer and check box Functions

Source: Internet
Author: User

I heard about jquery, but I have been amazed because the project is too busy to learn for a long time;

Recently, I am a little blank. In the following project, we need to use the "single region" and "check box" functions to spare time and sharpen the knife.

Jquery 1.3 api reference Chinese Version
Http://jquery-api-zh-cn.googlecode.com/svn/trunk/index.html

<SCRIPT src = "jquery-1.3.2.min.js"> </SCRIPT>

<Script language = "JavaScript">
$ (Document). Ready (function (){
VaR ul1_value = "";
VaR ul2_value = "";
$ ("# Ul1 li"). Click (function (){
$ (This). toggleclass ("checked ");

$ ("# Ul1 Li [class = 'checked']"). Each (function (){
Ul1_value = ul1_value + "," + $ (this). ATTR ("value ");
});

$ ("# Ul1_value"). Val (ul1_value );
Ul1_value = "";
});
$ ("# Ul2 li"). Click (function (){
$ (This). toggleclass ("checked ");
$ ("# Ul2 Li [value! = '"+ $ (This). ATTR (" value ") +"'] "). removeclass (" checked ");

If ($ (this). ATTR ("class") = "checked "){
Ul2_value = $ (this). ATTR ("value ");
}

$ ("# Ul2_value"). Val (ul2_value );
Ul2_value = "";
});
});
</SCRIPT>

<Style>
. Checked {
Background-color: # ff0000;
Font-weight: bold;
}
</Style>

Multiple selection box <input type = "text" id = "ul1_value"> <br/>
<Ul id = "ul1" value = "checkbox">
<Li value = "1" class = "checked"> Li1 </LI>
<Li value = "2"> li2 </LI>
<Li value = "3"> li3 </LI>
<Li value = "4"> LI4 </LI>
</Ul>
<Br/>

Single partition <input type = "text" id = "ul2_value"> <br/>
<Ul id = "ul2" value = "radio">
<Li value = "1" class = "checked"> Li1 </LI>
<Li value = "2"> li2 </LI>
<Li value = "3"> li3 </LI>
<Li value = "4"> LI4 </LI>
</Ul>
<Br/>

 

 

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.