简体   繁体   中英

html select tag to apply css

I would like to apply a css file after choosing an option from a html <select> tag.

I tried to use these links to existing css files.

<link rel="stylesheet" href="first.css" />
<link rel="stylesheet" href="second.css" />

How can I use them in <select> ?

    <select name="choose-an-option">
        <option value="first">
                            <!--use first.css here-->
        </option>
        <option value="second">
                            <!--use second.css here-->
        </option>
    </select>

You may want to look at this

Try this:

$("#choose-an-option").change(function() {
    $("link").attr("href", this.value + ".css");
)};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM