如何验证动态ID的HTML元素 [英] how to validate html elements with dynamic id
本文介绍了如何验证动态ID的HTML元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要验证HTML元素(一个文本字段),其 ID
动态通过数组赋值。下面我给我的HTML code。请给我如何设置HTML方向 ID
jQuery的?
< DIV CLASS =表单组NG重复=属性entity.entityPropertyTypes>
<! - 地产 - >
< DIV CLASS =COL-MD-3>
<标签类=控制标签> {property.propertyLabel}}< /标签>
< / DIV> <! - 值 - >
<! - 文本字段 - >
< DIV CLASS =COL-MD-3NG-IF =property.dataTypeId === 3>
<输入ID ={{property.propertyId}}值类型=文本级=表格控NG模型=property.propertyValue>
< / DIV> <! - 日期 - >
< DIV CLASS =COL-MD-偏移2 COL-MD-1NG-IF =property.dataTypeId === 4>
<日期选择日期格式=MM-YYYY>
<输入ID ={{property.propertyId}}年底类型=文本级=表格控NG模型=property.propertyValue>
< /日期选择器>
< / DIV>
解决方案
您可以添加任何你想要的属性,然后使用一个选择器来获取元素。
例如,可以将类添加到输入:
<输入ID ={{property.propertyId}}值类型=文本级=的形式控制MyClass的NG模型=property.propertyValue&GT ;
,然后按类选择
VAR textToCheck = $(input.myclass)VAL();
您甚至可以添加个人属性:
<输入项=1ID ={{property.propertyId}}值类型=文本级=表格控NG模型=财产.propertyValue>
然后
VAR textToCheck = $(输入[项目= 1])VAL()。
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();
这篇关于如何验证动态ID的HTML元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文