javascript - 关于注册表单的启用和禁用字段?
问题描述
我必须创建一个注册表单,其中包含名字、姓氏、地址、联系方式、电子邮件等字段。最初只有名字应该可见,因为我输入名字它应该启用姓氏,因为我输入姓氏它应该启用地址
解决方案
我对此有完全不同的看法。这种方法没有任何问题。事实上,有许多很酷的 UI 设计具有相同的术语。typeform.com 就是一个很好的例子。
这在 SO 是非常糟糕的做法,降低新用户评分有什么意义。
如果你不能给出正确的建议,那么你没有权利仅仅因为你没有理解他的观点而贬低他。
回答这个问题:如果它只是以错误的方式实现它,那将是一个非常糟糕的主意,用户可能会对此感到恼火。
最好使用 CSS 和 JS (jquery) 的组合来实现这一点,以获得美观、用户友好的 UI。
找到我使用 jQuery 创建的这个小片段可能会对您有所帮助。用一点 css 就可以让它看起来很棒!
在文本框中输入详细信息后按回车键。
jQuery.extend(jQuery.expr[':'], {
focusable: function(el, index, selector) {
return $(el).is('a, button, :input,[tabindex]');
}
}); // extention to jquery
$("#res").hide();
$("#email").hide();
$("#mobile").hide();
//Focuse Next on Enter press
$(document).on('keypress', 'input,select', function(e) {
if (e.which == 13) {
e.preventDefault();
var $focusable = $(':focusable');
var index = $focusable.index(document.activeElement) + 1;
if (index >= $focusable.length) index = 0;
$focusable.eq(index - 1).hide();
$focusable.eq(index).show();
$focusable.eq(index).focus();
}
});
function subscribeRelease() {
$("#res").show(200);
$(".btn").hide(200);
}
body,
html {
height: 100%;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.0/jquery.min.js"></script>
<div class="container-fluid h-100 justify-content-center">
<div class="row justify-content-center align-middle h-100">
<div class="col-10 text-center align-self-center">
<h1 style="font-size:40pt;">Register</h1>
<form id="register" class="form-inline justify-content-center">
<input type="text" class="form-control" id="name" placeholder="Name" /><br>
<input type="text" class="form-control" id="email" placeholder="Email" /><br>
<input type="text" class="form-control" id="mobile" placeholder="Mobile" /><br>
<br><br><br>
<button class="btn btn-info" onclick="subscribeRelease(); return false;">Submit!</button>
<span id="res"><h3 class="text-success">Registration Completed!</h3></span>
</form>
</div>
</div>
</div>
推荐阅读
- dynamics-crm - 如何调用自定义工作流活动(c# 代码)以启动休息调用按钮单击 IN Dynamics 365
- autodesk-forge - 工具栏上的按钮是如何激活的?
- python - 无法在 MacOS Big Sur 中从 OpenGL 导入 EGL
- c# - 找不到页面 - 剃须刀页面项目中的 .razor,Net 5.0
- python - 如何将过去 1 年和 6 个月的数据从 .txt 提取到两个由 '\t' 分隔的单独 .txt 文件中?
- python - 如何修复“@pytest.mark.parametrize,预期元组中的 PT006 错误名称类型”?
- sql - Snowflake 我们如何在字段数组上运行非透视查询而不是显式声明每个字段?
- asp.net-core - 我需要从 web.Config appSettings 访问值
- javascript - 在 useEffect 中更改数组值
- angular - 令牌到期后的角度登录