mẫu:remove tài sản cần thiết khỏi trường nhập vào mẫu nộp
[Display(Name = "City"]
[Required]
[RegularExpression(@"^(?!\d$).*$"]
[StringLength(20,MinimumLength = 2]
public string City { get; set; }
Mẫu:
@Html.LabelFor(x => x.City, new { @class = "control-label" })
@Html.TextBoxFor(x => x.City, new {id="city" })
Script:
<script>
$(document).ready(function() {
$("#identificationForm").submit(function (e) {
var required=document.getElementById("city").required;
console.log(required);
// e.preventDefault();
});
});
</script>
Tôi muốn loại bỏ tài sản cần thiết nếu một số điều kiện được đáp ứng Không thể làm điều này theo cách này. Làm thế nào tôi có thể đạt được điều này?
Với Jquery: $ ("# city"). RemoveAttr ("required"); hoặc sử dụng document.getElementById ("thành phố"). removeAttribute ('required'); – dz15
Bạn đang sử dụng JqueyVal? Nếu có, loại bỏ yêu cầu không phải là điều duy nhất! – Fals
có thể trùng lặp của [Làm cách nào để đặt thuộc tính bắt buộc HTML5 trong Javascript?] (Http: // stackoverflow.com/questions/18770369/how-to-set-html5-required-attribute-in-javascript) – vaxquis