I wrote a drop-down list plug-in with bugs. Could you please advise?

Source: Internet
Author: User

I wrote a drop-down list plug-in with bugs. Could you please advise?

Frontend UI sharing

; (Function ($) {$. fn. drowDowEditor = function (opts) {opts = jQuery. extend ({panel :$ (this), data: null}, opts ||{}); return this. each (function () {var panelID = opts. panel [0]. id; // -------- drop-down container ------------ var dropdownPanelHtml = ''; $ (dropdownPanelHtml ). insertAfter (opts. panel); var dropdownPanel = $ ("# drop_down_editor_panel" + panelID); // ---------------------------- // use DIV to locate the textbox and the drop-down container var container = ''; $ (container ). insertBefore (opts. panel); var editorContainer =$ ("# drop_down_editor_container" + panelID); opts. panel. appendTo (editorContainer); dropdownPanel. appendTo (editorContainer); opts.panel.css ("float", "left"); // -------- Add the drop-down button ----------- var button = ''; $ (button ). insertAfter (opts. panel); // --------------------------------- dropdownPanel.css ("top", "30px"); dropdownPanel.css ("left", "6px"); dropdownPanel. hide (); for (var I = 0; I <opts. data. length; I ++) {var dataItem = ''+ opts. data [I]. key + ''; dropdownPanel. append (dataItem);} dropdownPanel. find (". drop_item "). click (function () {alert (opts. panel [0]. id); opts.panel.val((%(this%.html () ;}); $ (". drop_item: odd "). mouseenter (function () {detail (this).css ("background-color", "# emerge 1b0") ;}); $ (". drop_item: odd "). mouseleave (function () {detail (this).css ("background-color", "white") ;}); $ (". drop_item: odd ").css (" background-color "," white "); opts. panel. click (function (e) {e. stopPropagation (); dropdownPanel. width (opts. panel. width () + 15 + 14); dropdownPanel. slideDown (300) ;}); $ (document ). click (function () {dropdownPanel. slideUp (300) ;}); opts.panel.css ("clear", "both") ;}}) (jQuery );
123123
$ ("# Dropdown "). drowDowEditor ({data: [{"key": "Baidu", "value": "www.baidu.com" },{ "key": "Sina", "value ": "www.sina.com.cn" },{ "key": "test", "value": "test.com" },{ "key": "blog", "value ": "cnblog.cn"}]}); $ ("# dropdown1 "). drowDowEditor ({data: [{"key": "Baidu 1", "value": "www.baidu.com" },{ "key": "Sina 1", "value ": "www.sina.com.cn" },{ "key": "test", "value": "test.com" },{ "key": "blog Garden 1", "value ": "cnblog.cn"}]});

Effect:

<喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + CjxpbWcgc3JjPQ = "http://www.2cto.com/uploadfile/Collfiles/20140827/20140827084910156.png" alt = "">

If you only render a basic rendering, and if there are multiple rendering, the overwriting problem occurs,

I am new to the web. I hope you can give more advice. Frontend sharing

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.