简体   繁体   English

在DropDownList http helper ASP.NET MVC中添加JavaScript事件

[英]Add javascript event in DropDownList http helper ASP.NET MVC

I have this code: 我有以下代码:

<div class="col-xs-6 col-sm-3">
        @Html.DropDownList("cssFiles", (IEnumerable<SelectListItem>)ViewBag.cssFiles, "Crear Nuevo", new { @class = "form-control", @id = "selCssFile" })
        <span>
            <input type="text" class="form-control" id="txtFileName" style="display:none;" placeholder="Nombre del archivo">
        </span>
</div>

I want to add a Javascript event for show the "txtFileName" when "Crear Nuevo" is select, and hide it when the dropdown change 我想添加一个Javascript事件,以便在选择“ Crear Nuevo”时显示“ txtFileName”,并在下拉菜单更改时将其隐藏

Basically you need to attach click event on your dropdown element. 基本上,您需要在下拉元素上附加click事件。

Code

$('#selCssFile').on('change',function(){
   //implement code after selected the option
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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