-
Qyouu
我找到了真正的答案。如果您愿意,这些期望被命名为“输入掩码”。您必须使用 3. 方库。其中一些在以下网站中列出:图书馆 1 图书馆 2我选择Cleave.js了你的问题。这是演示:<script src="https://nosir.github.io/cleave.js/dist/cleave.min.js"></script><script src="https://nosir.github.io/cleave.js/dist/cleave-phone.i18n.js"></script><script> function loadFunction() { // custom var cleaveCustom = new Cleave('.input-custom', { blocks: [1, 3, 3, 2, 2, 3, 3], delimiter: ' ', }); }</script><body onload="loadFunction()"> A 936 447 02 40 ZGS 001 <div class="container"> <input class="input-custom" placeholder="Custom delimiter & blocks" /> </div></body>
-
波斯汪
如果我们假设用户必须一个一个地写字符。这将起作用。<body> <input type="text" class="form-control" id="ds" name="ds" onkeypress="keyPress()" maxlength="23"></body><script> function keyPress() { var field = document.getElementById("ds"); var text = field.value; if(text.length == 1 || text.length == 5 || text.length == 9 || text.length == 12 || text.length == 15 || text.length == 19 ) { var newText = text + " "; field.value = newText; } }</script>
-
UYOU
这是一个小例子。<div class="childDumpFile"> <label for="ds">Dataset</label> <input type="text" class="form-control" id="ds" name="ds"></div><div class="test_ds"></div>带有 jquery 的 JS。$("#ds").change(function(){ var ds_value = $("#ds").val();var temp = ds_value;temp = temp.substring(0,1) + " " + temp.substring(1, 4) + " " + temp.substring(4, 7) + " " + temp.substring(7, 9) + " " + temp.substring(9, 11) + " " + temp.substring(11, 14) + " " + temp.substring(14, 17); $("#ds").val(temp); $(".test_ds").html(temp);});这是一个演示 - https://jsfiddle.net/Kistlak/7bkdtev8
-
慕桂英546537
首先,您需要在输入中添加 onchange="getTimeNow()" oninput="getTimeNow()"<input type="text" class="form-control" id="ds" name="ds" value="{{Request::get('ds') ?? ''}}" onchange="getTimeNow()" oninput="getTimeNow()">最后,您将获得事件输入文本<script>function getTimeNow(){console.log(new Date())}</script>