【问题标题】:Change color of label text when radiobutton is selected选择单选按钮时更改标签文本的颜色
【发布时间】:2016-03-30 19:41:19
【问题描述】:

我有一个 MVC 视图,带有一个标签和两个单选按钮。 What I am trying to do is, when the radiobutton "Dark" is selected, the text color in the label should change to black and when the radiobutton "Light" is selected the text color should change to white.

型号:

 public class SetupThemeModel
{
    public bool IsFontColorDark { get; set; }
}

控制器:

public ActionResult LabelText(SetupThemeModel model)
    {

        return View(model);
    }

查看:

                                        @using (Html.BeginForm())
                                    {
                                        <label>
                                            @Html.RadioButtonFor(m => m.IsFontColorDark, "false", new { id = "Light" })
                                            @Html.Label("Light", "Light Font Color")
                                        </label><br />

                                        <label>
                                            @Html.RadioButtonFor(m => m.IsFontColorDark, "true", new { id = "Dark" })
                                            @Html.Label("Dark", "Dark Font Color")                                                
                                        </label>

                                        <input type="submit" value="Try" class="btn btn-danger" />
                                    }    

还有标签:
&lt;h1&gt;&lt;span class="label label-default h1" id="text" style="background-color:#ffd800"&gt;Sample Text&lt;/span&gt;&lt;/h1&gt;
我试图通过标签 ID 传递颜色,但我被卡住了,我不知道如何继续。

【问题讨论】:

  • 您应该使用javascriptjQuery 来执行此操作。

标签: asp.net-mvc razor radio-button


【解决方案1】:

你可以这样写:

.red{
   color : red;
   background-color: red;
 }

 @Html.Label("Light", "Light Font Color", htmlAttributes: new { @class = "red" })

【讨论】:

  • 我想通过模型传递值
猜你喜欢
  • 1970-01-01
  • 2011-08-29
  • 2019-12-03
  • 1970-01-01
  • 1970-01-01
  • 2013-07-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多