【问题标题】:The placeholder value of a text box is not changing to original value?文本框的占位符值不会更改为原始值?
【发布时间】:2021-12-23 03:17:24
【问题描述】:

我有一个 cshtml/razor html 文件,其中有一个具有占位符值的文本框。占位符值根据用户单击的单选按钮而变化。例如,如果用户选择单选按钮酒店,则占位符值将设置为“请输入城市”,如果用户单击“空中”单选按钮,占位符的值将设置为“请输入机场”。一旦我继续从各种单选按钮移动,占位符的值就会发生变化最终在空中单选按钮时出现的占位符的值给出了其他单选按钮占位符的值

@Html.TextBoxFor(m => m.airTravelComponentSubRequestOneWay.DepartureAirport, new { @placeholder = @Resource.CityAirport, @id = "SearchViewModels_airTravelComponentSubRequestRoundTrip_DepartureAirport", @class = "search-element-master small-12 pad10", autocomplete = "off" })

这是文本按钮的html

【问题讨论】:

    标签: javascript c# html asp.net-core razor


    【解决方案1】:

    你可以尝试用js来改变占位符:

    <input type="radio" id="hotel" value="hotel"  name="type"/>hotel
    <br />
    <input type="radio" id="air" value="airport" name="type"/>air
    <br />
    <input type="radio" id="other" value="other" name="type"/>other
    <br />
    @Html.TextBoxFor(m => m.airTravelComponentSubRequestOneWay.DepartureAirport, new { @placeholder =  @Resource.CityAirport, @id = "SearchViewModels_airTravelComponentSubRequestRoundTrip_DepartureAirport", @class = "search-element-master small-12 pad10", autocomplete = "off" })
    

    js:

    $("input[name='type']").click(function () {
                var placeholder = "Please enter the " + $(this).val();
                $("#SearchViewModels_airTravelComponentSubRequestRoundTrip_DepartureAirport").attr("placeholder", placeholder);
                
            });
    

    结果:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-12-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-09
      • 1970-01-01
      • 2014-03-18
      相关资源
      最近更新 更多