Home >Web Front-end >JS Tutorial >The select tag simulation/beautification method uses JS plug-in_jquery

The select tag simulation/beautification method uses JS plug-in_jquery

WBOY
WBOYOriginal
2016-05-16 17:38:491513browse

The appearance of the

.
Advantages: Still using tag that needs to be beautified. We use a class name "beautify" to determine it. There is no < of this style. select> will be ignored
var selects = $("select.beautify");
if (selects.length > 0) {
//First add a

at the bottom of the code, Used to host and display drop-down box options
$("body").append("");
//Beautify them one by one
selects.each(function () {
//Set an alias for this (that is, , .dummy will be used for our special style definition of this type of
//At the same time, //After creation, insert this into the dom, followed by the original ")
.attr("disabled", this.disabled)
.css("width", parseInt(this.style.width ) "px")
.css("display", this.style.display)
.insertAfter(this)
.val(this.options[this.selectedIndex].text);
//Hide is clicked
input.click(function () {
// Call out the previously created
and clear the content
// Pass the style sheet of by default
$(select).hasClass("extend")
? div.css ("width", "")
: div.css("width", $(this).innerWidth());
//Copy