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>