在变化DropDownListFor值更改标签 [英] Change label on change DropDownListFor value

查看:183
本文介绍了在变化DropDownListFor值更改标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用 DropDownListFor 和我的页面上的标签文本。

I use a DropDownListFor and a label text on my page.

<%=Html.DropDownListFor(x => x.MotiveClientType,
                        new SelectList(
                            Model.ClientMotives, "Id", "Label", Model.MotiveClientType),
                        new { id = "ddlMotiveClientType" }
)%>                       

我如何选择价值时,改变我的标签我的 DropDownListFor

推荐答案

我不知道任何功能原产于ASP.NET MVC,可以让你做到这一点,但用jQuery做它是一个相当微不足道的小事。下面是挂接一个事件处理程序的下拉和放大器的改变事件的一个例子。然后设置标签文本:

I'm not aware of any functionality native to ASP.NET MVC that will allow you to do this, but doing it with jQuery is a fairly trivial matter. Here's an example of hooking up an event handler to the change event of the dropdown & then setting the label text:

$("#DropDownID").change(function () {
    $("#LabelID").text("Your text here");
});

就有关值替换的ID。

Just replace the IDs with the relevant values.

这篇关于在变化DropDownListFor值更改标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆