新建一个js文件并保存为select.js,剩下的工作我们全部在这个js中去完成。
函数名:loadSelect(obj);
参数:select对象
相关函数:
Home > Web Front-end > JS Tutorial > How to beautify select using javascript_form effects

How to beautify select using javascript_form effects

WBOY
Release: 2016-05-16 19:14:18
Original
984 people have browsed it

People in forums often ask how to beautify the Select tag using CSS. In fact, everything you see that is cool is done using JavaScript. I tried it yesterday and basically implemented the primary function. Take it out and share it with everyone. You can first take a look at the preview effect: http://www.iwcn.net/demo/select.
【Functional Requirements】
1. It should be convenient to call. When done, it should look like this:

Copy code Code As follows:

function loadSelect(selectobj){
//Passing in a select object can beautify its style
}

2. No Change the original form items without destroying the page code of the form:
Copy the code The code is as follows:



>                                                                                                   🎜>                                                                             🎜>                                                                           ="province"> ; 🎜>



[Implementation Idea]

Step one: Hide the select in the form.
Why? It's simple, because this guy is too stubborn and can't get what you want using CSS. So kill it.

Step 2: Use a script to find the absolute position of the select tag on the web page.
We use DIV tags to make a fake and better-looking one at that position to serve as his stand-in.

Step 3: Use a script to read the value in the select tag.
Although it is hidden, we can still use the options in it, so we can take them all.

Step 4: When the user clicks on the avatar of the select tag, which is the div. We use another div to float below the previous div. This is the stand-in for options.

That’s roughly it, let’s implement it step by step!

【Preparation】
1. Think about how you want to beautify the selection and prepare the corresponding pictures. I prepared two small pictures, which are drop-down arrow 1 and drop-down arrow 2. 1 is the default style and 2 is the style when the mouse is moved over.
2. Write a common form submission page, such as the one below. Note that I defined the basic CSS style for select, added the code to call the js file in the head, and added the script to call the function in the body.
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template