简体   繁体   English

文本框的占位符值未更改为原始值?

[英]The placeholder value of a text box is not changing to original value?

I have a cshtml/razor html file where in there is a text box which has a placeholder value.The placeholder values change based on the radio button which the user clicks.Eg if the user selects the radio button hotel,then the placeholder value will set to "Please enter the city" and if the user click "air" radio button the value of place holder is set to "Please enter the airport".Once i keep moving from various radio buttons the value of place holder chnages and ultimately the value of place holder which comes at time of air radio button gives value of other radio button place holder我有一个 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" })

This is the html for the text button这是文本按钮的 html

You can try to use js to change the placeholder:可以尝试使用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: js:

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

result:结果:

在此处输入图片说明

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

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