javascript - jQuery更改不适用于动态元素
问题描述
我有一个输入,如果长度小于 1,我想显示一个图标 X。如果长度大于 1,我想打印一个刻度图标:
为此,我想使用函数 change、keyup 和 focusout。
这个功能不起作用,因为我不知道如何正确识别输入。我不能使用输入的 ID,因为该 ID 是动态的。
我试过使用它:
$( "filaa-enq" ).change(function()
$( "filaa-enq" ).keyup(function()
$( "filaa-enq" ).focusout(function()
<div class="input">
<label class="text-mida">
<div class="fila-enq"><input class="filaa-enq" type="input" name="question_1_1_0" value="" maxlength="20" id="question_1_1_0"><span style="display:none" class="validate_ok_enquesta fa fa-check"></span><span style="display:none" class="validate_ko_enquesta fa fa-times"></span></div>
</label>
</div>
$( ".filaa-enq" ).keyup(function() {
console.log("ttttt");
checkEnquesta(this);
});
$( "filaa-enq" ).focusout(function() {
console.log("test");
checkEnquesta(this);
});
$( "filaa-enq" ).change(function() {
console.log("changees");
checkEnquesta(this);
});
function checkEnquesta(element){
console.log(element);
if (element.value=="") {
$('#'+element.id).siblings(".validate_ko_enquesta").hide();
$('#'+element.id).siblings(".validate_ok_enquesta").hide();
return false;
}
if (element.value.length > 1 ){
$('#'+element.id).siblings(".validate_ok_enquesta").show();
$('#'+element.id).siblings(".validate_ko_enquesta").hide();
}
else{
$('#'+element.id).siblings(".validate_ko_enquesta").show();
$('#'+element.id).siblings(".validate_ok_enquesta").hide();
}
}
.validate_ok_enquesta{
float: right;
margin-right: 6px;
margin-top: -35px;
position: relative;
z-index: 2;
color:green;
}
.validate_ko_enquesta{
float: right;
margin-right: 6px;
margin-top: -35px;
position: relative;
z-index: 2;
color:red;
}
我怎样才能传递身份证?如果那个id是动态的?
解决方案
推荐阅读
- javascript - 在 Next.js 中动态获取 SVG 图标
- java - 压缩具有相同 id 的行
- django - Django Rest Framework:将值附加到 ListAPIView
- php - 如何从 MySQL 中的另一个表中获取数据?
- javascript - 选中的框不会在 md-table 中保持选中状态
- c# - 将 2 个查询的结果添加到单个列表中,然后对其进行排序
- r - R中的加权连接或匹配
- google-apps-script - 使用 ImportJSON 将数据导入 Google 表格,根据列名选择值输出?
- java - Andorid App 没有自动识别位置
- javascript - 我可以对单个结果进行多个开玩笑测试吗?