I need to validate an HTML element (a text field) whose id
is dynamically assigned through an array. I have given my HTML code below. Please give me a direction on how to set the HTML id
in jQuery?
<div class="form-group" ng-repeat="property in entity.entityPropertyTypes">
<!-- PROPERTY -->
<div class="col-md-3">
<label class="control-label">{property.propertyLabel}}</label>
</div>
<!-- VALUE -->
<!-- Text field -->
<div class="col-md-3" ng-if="property.dataTypeId === 3 ">
<input id="{{property.propertyId}}Value" type="text" class="form-control" ng-model="property.propertyValue">
</div>
<!-- Date -->
<div class="col-md-offset-2 col-md-1" ng-if="property.dataTypeId === 4 ">
<datepicker date-format="MM-yyyy">
<input id="{{property.propertyId}}yearEnd" type="text" class="form-control" ng-model="property.propertyValue">
</datepicker>
</div>
You can add any property you want and then use a selector to get the element.
For example, you could add a class to the input:
<input id="{{property.propertyId}}Value" type="text" class="form-control myclass" ng-model="property.propertyValue">
and then select by class
var textToCheck = $("input.myclass").val();
You can even add a personal attribute:
<input item="1" id="{{property.propertyId}}Value" type="text" class="form-control" ng-model="property.propertyValue">
and then
var textToCheck = $("input[item=1]").val();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.