我正在创建一个 MVC 应用程序。我有一个模型,它具有布尔值和显示名称以及一个文本框。目的是每当在文本框中进行一些更改时,该名称应反映在复选框显示名称中。
模型:
[Required(ErrorMessage = "Please Enter Account Number")]
[Display(Name = "Account Number")]
public string AccountNumber{ get; set; }
[Display(Name = "You approving whatever you entered- Your enter AccountNumber is ")]
[Range(typeof(bool), "true", "true", ErrorMessage = "Please accept the Terms and Conditions by clicking the check the box!")]
public bool TermsAndConditions { get; set; }
看法:
<div class="form-group">
@Html.LabelFor(model => model.AccountNumber, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.AccountNumber, new { htmlAttributes = new { @class = "form-control" } })
</div>
</div>
<div class="form-group">
@@Html.CheckBoxFor(x => x.TermsAndConditions)
@Html.LabelFor(model => model.TermsAndConditions)
@Html.ValidationMessageFor(x => x.TermsAndConditions)
</div>
JS:
$(function () {
$("#AccountNumber").keyup(function () {
var text= $("#AccountNumber").val();
alert('You type: '+text);
$("#TermsAndConditions").val(text);
});
});
当我运行该页面时,无论我在帐号中做什么更改,我都可以打印文本。但我无法将该值分配给复选框显示值。请帮我。
$("#TermsAndConditions").html(text);
试试这个它对我有用。由于只有输入类型可以使用值。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句