jquery - 输入已填充时显示 div
问题描述
如果所有输入都已填充在第一个 div 中,我想显示下一个 div
我已经设法在父元素内完成这项工作
<fieldset>
test fieldset 1
<form>
<div class="row active-q">
test 1
<input type="text">
</div>
<div class="row active-q">
test 2
<input type="text">
</div>
<div class="row active-q">
test 3
<input type="text">
</div>
</form>
<fieldset>
<fieldset>
test fieldset 2
<form>
<div class="row active-q">
test 4
<input type="text">
</div>
</form>
</fieldset>
//input check for filled / empty to display another one
$('input[type="text"],input[type="radio"],input[type="checkbox"], select').bind(
"keyup change", function () {
// get elements that are empty.
var empty = $(
'input[type="text"], input[type="radio"],input[type="checkbox"], select'
).map(function (index, el) {
return !$(el).val().length ? el : null;
}).get();
// could also be placed outside of the function
var number = $(this).closest(".active-q").next();
// check if there are any empty elements, if there are none, show numbers, else hide number.
!empty.length ? number.hide() : number.show().css("display", "flex");
}
);
我的问题是,如果所有 active-q 都已填满,我如何显示下一个字段集? https://codepen.io/nikolamilovac/pen/Paqvvb
解决方案
首先创建两个带有 id 的 div(您也可以设置字段集的 id 并在 onchange 函数上简单地显示隐藏,这里我关注 div )并设置在填充完所有字段后不显示要打开的第二个 div -
<div id="div1">
<input type="text" id="text1" />
<input type="text" id="text2" />
</div>
<div id="div2" style="display:none;">
<input type="text" id="text3" />
<input type="text" id="text4" />
</div>
然后在要打开新div的最后一个文本框上创建简单的更改功能,如果所有字段都已填充,则在更改功能上将显示第二个div,否则它将抛出消息以填充所有字段-
$("#text2").change(function(){
var one=$('#text1').val();
var two=$('#text2').val();
if(one!="" && two!="")
{
$('#div2').show();
return true;
}
else
{
alert('Please fill all the field');
return false;
}
});
希望它会帮助你。
推荐阅读
- python - 如何使用 Selenium 和 Python 单击动态 Web 表中可用的按钮
- python - 反馈表 Django
- javascript - 根据验证设置对象的值
- python - 如何修复此名称未定义错误?
- flutter - gsheets颤动如何添加凭据
- javascript - ReferenceError:未定义 XMLHttpRequest 谷歌应用脚本
- javascript - 通过 JQuery AJAX 调用保存文件
- java - 使用 ResponseStatusException 时如何记录异常信息
- html - 从 excel 单元格保存 html 文件
- javascript - `npx webpack-dev-server` 时,webpack-dev-server 引发“未找到模块:错误:无法解析”