Use CSS and jquery to simulate a select and attach the code that gets the data after submitting _jquery

Source: Internet
Author: User
Simulate a select with code to obtain data after submission

HTML Code
Copy Code code as follows:

<div id= "Dropdown" >
<p> Please select City </p>
<ul>
<li><a href= "#" rel= "2" > Beijing </a></li>
<li><a href= "#" rel= "3" > Shanghai </a></li>
<li><a href= "#" rel= "4" > Wuhan </a></li>
<li><a href= "#" rel= "5" > Guangzhou </a></li>
</ul>
</div>
<div id= "Result" ></div>

JavaScript Code
Copy Code code as follows:

<script type= "Text/javascript" >
$ (function () {
$ ("#dropdown p"). Click (function () {
var ul = $ ("#dropdown ul");
if (Ul.css ("display") = = "None") {
Ul.slidedown ("fast");
}else{
Ul.slideup ("fast");
}
});
$ ("#dropdown ul li a"). Click (function () {
var txt = $ (this). text ();
$ ("#dropdown p"). html (TXT);
var value = $ (this). attr ("rel");
$ ("#dropdown ul"). Hide ();
$ ("#result"). HTML ("You have selected" +txt+ ", the value is:" +value);
});

});
</script>

CSS Code
Copy Code code as follows:

#dropdown {width:186px; margin:100px auto; position:relative}
# dropdown p{width:150px; height:24px; line-height:24px; padding-left:4px; padding-right:30px; border:1px solid #a9c9e2; Background: #e8f5fe URL (arrow.gif) no-repeat rightright 4px; Color: #807a62; Cursor:pointer}
#dropdown ul{width:184px; background: #e8f5fe; margin-top:2px; border:1px solid #a9c9e2; Position: absolute; Display:none}
#dropdown ul li{height:24px line-height:24px text-indent:10px}
#dropdown ul li A{display:block ; height:24px; Color: #807a62; Text-decoration:none}
#dropdown ul li a:hover{background: #c6dbfc; color: #369}
#result {margin-top:10px; Text-align:center}
Related Article

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.