Jquery + css implementation drop-down list, jquerycss implementation drop-down

Source: Internet
Author: User

Jquery + css implementation drop-down list, jquerycss implementation drop-down

<! DOCTYPE html>
<Html>
<Head>
<Meta charset = "UTF-8">
<Title> fruit </title>
<Style type = "text/css">

. Hide {
Display: none;
}
Div {
Float: left;
Width: 100%;
}
. Selector-containter {
Margin-bottom: 10px;
}
. Selector {
Width: 200px;
Background: # FFF;
Border: 1px solid # DDD;
}
. Selector-hint {
Width: 178px;
Border: 1px solid # DDD;
}
. Selector-expand {
Width: 8px;
Border: 1px solid # DDD;
}
. Selector-collapse {
Width: 8px;
Border: 1px solid # DDD;
}
</Style>
<Script src = "jquery-3.2.1.min.js"> </script>
<Script>
$ (Document). ready (function (){

// Use the on method and the event Delegate mechanism. The content in selector-option-container is dynamically appended.
$ ('. Selector'). on ('click', '. selector-expand', function (){
$ (This). parent (). children ('. selector-option-iner'). children (). remove ();
$ (This ). parent (). children ('. selector-option-iner '). append ('<div> <input type = "checkbox" name = "fruitGroup" class = "selector-checkbox"/> </div> <div class = "selector-option"> javascot </div> ');
$ (This ). parent (). children ('. selector-option-iner '). append ('<div> <input type = "checkbox" name = "fruitGroup" class = "selector-checkbox"/> </div> <div class = "selector-option"> banana </div> ');

$ (This). nextAll ('. selector-option-iner'). removeClass ('hide ');
});

$ ('. Selector'). on ('click', '. selector-collapse', function (){
$ (This). nextAll ('. selector-option-iner'). addClass ('hide ');
});

$ ('. Selector-t1'). on ('click', '. selector-option', function (){
$ (This). parent (). parent (). children ('. selector-hint'). text ($ (this). text ());

$ (This). parent (). addClass ('hide ');
});

$ ('. Selector-t1 '). on ('click','. selector-checkbox', function (){
$ (This ). parent (). parent (). parent (). children ('. selector-hint '). text ($ (this ). parent (). next (). text ());

// Use the prop method to assign values to properties with Boolean values
$ (This). prop ('checked', false );

$ (This). parent (). parent (). addClass ('hide ');
});
});
</Script>
</Head>
<Body>
<Div id = "titan" class = "selector-containter">
<Div id = "fruit">
<Div class = "selector">
<Div class = "selector-hint"> select fruit </div>
<Div class = "selector-expand"> + </div>
<Div class = "selector-collapse">-</div>
<Div class = "selector-option-container">
</Div>
</Div>
</Div>
</Div>
<Div id = "athena" class = "selector-t1 selector-containter">
<Div id = "fruit">
<Div class = "selector">
<Div class = "selector-hint"> select fruit </div>
<Div class = "selector-expand"> + </div>
<Div class = "selector-collapse">-</div>
<Div class = "selector-option-container">
</Div>
</Div>
</Div>
</Div>
</Body>
</Html>

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.