简体   繁体   中英

Add style to html.dropdownlist when using javascript function on change

I want to add background color to this drop down.. how can I do this.. I tried adding new{style="background-color: #fff;"} to the below code.. but this does not seem to working..

     <%=Html.DropDownList("dd", 
                       new List<SelectListItem>
         {
            new SelectListItem{ Text="dd1", Value = "dd1" }, 
            new SelectListItem{ Text="dd2", Value = "dd2" }

         }
                            , new { onchange = "jsfunc()" } 


         )%>

I tried:

     <%=Html.DropDownList("dd", 
                       new List<SelectListItem>
         {
            new SelectListItem{ Text="dd1", Value = "dd1" }, 
            new SelectListItem{ Text="dd2", Value = "dd2" }

         }
                            , new { onchange = "jsfunc()" }
                            , new {style="background-color: #fff;"}


         )%>

You should avoid using inline styles. I suggest creating a class and the syntax would be

new { @class = "yourclass", @onchange = "jsfunc()" }

I think you had a syntax error, new {@style = "background-color: #fff"} , but you should use a class instead.

Edit

new { @onchange = "jsfunc()", @style = "background-color: #fff"}

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