Using jquery to implement select down box editing status (1/2)

Source: Internet
Author: User

The following example is the use of jquery to implement the Select down box editing state, it can dynamically make select into a modified state oh, see the example below, mainly through the CSS Tutorial style sheet clip to achieve. Compatible ie6-8, Google, Firefox and so on.

<!doctype HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/ Xhtml1-transitional.dtd ">
<title> The Down box implementation method that can be edited--woody.wu</title>
<style type= "Text/css" >
. cssinput
{
height:19px;
padding:3px;
padding-left:3px;
padding-right:0px;
margin:0px;
border:1px solid #c0c0c0;
Font-family: Song body, Arial;
font-size:9pt;
}
. select_div_list
{
Position:absolute;
BORDER:1PX solid black;
Background-color:white;
Overflow:hidden;
Overflow-y: auto;
}
. Select_div_list_ul
{
margin:0px;
padding:0px;
List-style-type:none;
}
. Select_div_list_ul Li
{
Cursor:pointer;
padding-left:3px;
Font-family: Song body, Arial;
font-size:9pt; *padding:0px;*height:20px;_height:14px;_margin:0px;_height:14px;*margin:0px;line-height:14px;}
. Selectspan
{
Background-color:yellow;
}
</style>
<script type= "text/web Effects" src= "Js/jquery-1.4.2.min.js" ></script>
<script type= "Text/javascript" >
var inputID = "INPUT1";
var Selectid = "Select1";
var Widt = 0;
var inputwi = 0;
var he = 0;
$ (function () {
inputID = "INPUT1";
Selectid = "Select1";
Widt = 200;
Inputwi = widt-20;
He = $ ("#user"). Height ()-41;
var offset = $ ("input[id=input1]"). Offset ();
$ ("#" + Selectid). Change (function () {
var Newvar = $ ("#" + Selectid). Find ("option:selected"). Text ();
$ ("#" + inputID). Val (Newvar);
). Click (function () {
$ ("#select_div_on_key" + selectid). Remove ();
}. css ({"Display": "Block", "width": Widt + "px", "Z-index": 1, "clip": "Rect (0px" + Widt + "px 51px 151px)"});
$ ("#" + inputID). KeyUp (function () {
Showselectcombo ();
). Click (function () {
Showselectcombo ();
}). css ({"Z-index": 2, "width": Inputwi + "px"});;
});
function Showselectcombo () {
var pob = $ ("#" + inputID);
var v = pob.val ();
var off = Pob.offset ();
var wi = pob.width () + 16;
var tp = off.top + pob.height ()-100 + 7;
var lef = off.left-200 + 2;
var html = "<div class= ' select_div_list ' id= ' Select_div_on_key" + Selectid + "' style= ' width:" + wi + "Px;top:" + TP + "Px;left:" + lef + "px;" ><ul class= ' select_div_list_ul ' > ';
$ ("#" + Selectid). Find ("option"). each (function () {
var tk = $ (this);
HTML + + "<li val= '" + tk.val () + "' ht= '" + encodeURIComponent (tk.html ()) + "' >" + tk.html (). Replace (V, "<span cl ass= ' Selectspan ' > ' + V + "</span>") + "</li>";
});

Home 1 2 last page

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.