- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
根据我的要求,用户只能从页面上提供的键盘输入数字。所以输入字段是只读的。
现在我想知道的是,当用户开始输入月份时,其他文本应保留在文本字段中,直到用户键入该内容为止。例如05/DD/YYYY 这样。因此,该文本将被隐藏。
如果我放置占位符,那么当用户开始输入数字时,所有文本都会消失。我不想要那个。所以我在单独的 span 标签
中使用了“MM/DD/YYYY”文本。
var Memory = "0", // initialise memory variable
Current = "", // and value of Display ("current" value)
Operation = 0, // Records code for eg * / etc.
MAXLENGTH = 8; // maximum number of digits before decimal!
function format(input, format, sep) {
var output = "";
var idx = 0;
for (var i = 0; i < format.length && idx < input.length; i++) {
output += input.substr(idx, format[i]);
if (idx + format[i] < input.length) output += sep;
idx += format[i];
}
output += input.substr(idx);
return output;
}
function AddDigit(dig) { //ADD A DIGIT TO DISPLAY (keep as 'Current')
if (Current.indexOf("!") == -1) { //if not already an error
if ((eval(Current) == undefined) &&
(Current.indexOf(".") == -1)) {
Current = dig;
document.calc.display.focus();
} else {
Current = Current + dig;
document.calc.display.focus();
}
Current = Current.toLowerCase(); //FORCE LOWER CASE
} else {
Current = "Hint! Press 'Clear'"; //Help out, if error present.
}
if (Current.length > 0) {
Current = Current.replace(/\D/g, "");
Current = format(Current, [2, 2, 4], "/");
}
document.calc.display.value = Current.substring(0, 10);
document.getElementById("cursor").style.visibility = "hidden";
}
function Clear() { //CLEAR ENTRY
Current = "";
document.calc.display.value = Current;
document.calc.display.focus();
document.getElementById("cursor").style.visibility = "visible";
//setInterval ("cursorAnimation()", 5000);
}
function backspace() {
Current = document.calc.display.value;
var num = Current;
Current = num.slice(0,num.length - 1);
document.calc.display.value = Current;
document.calc.display.focus();
document.getElementById("cursor").style.visibility = "hidden";
}
function cursorAnimation() {
$("#cursor").animate({
opacity: 0
}, "fast", "swing").animate({
opacity: 1
}, "fast", "swing");
}
//--------------------------------------------------------------->
$(document).ready(function() {
document.getElementById("cursor").style.visibility = "visible";
//setInterval ("cursorAnimation()", 1000);
});
.intxt1 {
padding: 16px;
border-radius: 3px;
/* border: 0; */
width: 1017px;
border: 1px solid #000;
font-family: Droid Sans Mono;
background: #fff;
}
.txtplaceholder {
font-family: "Droid Sans Mono";
color: #D7D7D7;
position: relative;
float: left;
left: 219px;
top: 17px;
z-index: 10 !important;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
display: inline-block;
}
#cursor {
position: relative;
z-index: 1;
left: 32px;
top: 2px;
visibility: hidden;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js"></script>
<form Name="calc" method="post">
<div style="position:relative">
<span id="cursor">_</span>
<span class="txtplaceholder">MM/DD/YYYY</span>
<span style="z-index:100">
<input class="intxt1" autocomplete="off" id="pt_dob" name="display" value="" type="text" readonly>
</span>
<button class="cancel-icon" type="reset" onClick="Clear()"></button>
</div>
<div class="num_keypad1" style=" margin-top:19px;">
<!-- Screen and clear key -->
<div class="num_keys">
<!-- operators and other keys -->
<span id="key1" onClick="AddDigit('1')">1</span>
<span id="key2" onClick="AddDigit('2')">2</span>
<span id="key3" onClick="AddDigit('3')">3</span>
<span id="key4" onClick="AddDigit('4')">4</span>
<span id="key5" onClick="AddDigit('5')">5</span>
<span id="key6" onClick="AddDigit('6')">6</span>
<span id="key7" onClick="AddDigit('7')">7</span>
<span id="key8" onClick="AddDigit('8')">8</span>
<span id="key9" onClick="AddDigit('9')">9</span>
<span id="key0" onClick="AddDigit('0')" style="width: 200px;">0</span>
<span id="keyback" class="clear" onClick="backspace()"> <div class="num_xBox">X</div></span>
</div>
</div>
</form>
出现的问题如下:
我的数字位于文本“MM/DD/YYYY”下方。我不知道如何让我的数字高于该文本
我应该如何隐藏用户输入的文本并相应地显示其他文本,例如如果用户输入 05 并显示其他文本,如“05/DD/YYYY”,“MM”应该隐藏。
谁能帮我解决这个问题?
注意: 使用 input type=date 或任何其他插件,我可以实现上述功能,但我的要求不同。我必须仅使用 HTML、CSS 和 JS 来实现。
最佳答案
我会为这类事情使用现成的数据选择器,因为它会内置所有错误检查功能,以确保您以正确的格式输入日期。
你这样做的方式是,在你输入月份之前,你无法检查日期是否有效,到那时用户将不得不退格,这将是一个非常缓慢和笨拙的过程,这不是非常用户友好。
无论如何,如果您坚持使用数字键盘,我会这样做。
下面是上面的一个非常简单的例子
var dateBits = ["D", "D", "M", "M", "Y", "Y", "Y", "Y"],
letters = ["D", "D", "M", "M", "Y", "Y", "Y", "Y"],
input = document.getElementById('pt_dob'),
currentIndex = 0;
function makeDate() {
return dateBits[0] + dateBits[1] + "/" + dateBits[2] + dateBits[3] + "/" + dateBits[4] + dateBits[5] + dateBits[6] + dateBits[7];
}
function AddDigit(number) {
dateBits[currentIndex] = number;
if (currentIndex < 8) {
currentIndex++;
}
input.value = makeDate();
}
function RemoveDigit() {
if (currentIndex > 0) {
currentIndex--;
}
dateBits[currentIndex] = letters[currentIndex];
input.value = makeDate();
}
function Clear() {
for (i = 0; i < letters.length; i++) {
dateBits[i] = letters[i];
}
currentIndex = 0;
input.value = makeDate();
}
input.value = makeDate(); // run this line onload or include this whole script at the bottom of the page to get your input to start with your text
.intxt1 {
padding: 16px;
border-radius: 3px;
/* border: 0; */
width: 1017px;
border: 1px solid #000;
font-family: Droid Sans Mono;
background: #fff;
}
#cursor {
position: relative;
z-index: 1;
left: 32px;
top: 2px;
visibility: hidden;
}
.num_keys > span {
display: inline-flex;
width: 2em;
height: 2em;
align-items: center;
justify-content: center;
cursor: pointer;
border: 1px solid black;
}
<form Name="calc" method="post">
<div style="position:relative"><span id="cursor">_</span>
<span class="txtplaceholder">MM/DD/YYYY</span><span style="z-index:100"><input class="intxt1" autocomplete="off" id="pt_dob" name="display" value="" type="text" autocomplete="off" readonly></span>
<button class="cancel-icon" type="reset" onClick="Clear(); return false;">clear</button>
</div>
<div class="num_keypad1" style=" margin-top:19px;">
<!-- Screen and clear key -->
<div class="num_keys">
<!-- operators and other keys -->
<span id="key1" onClick="AddDigit('1')">1</span>
<span id="key2" onClick="AddDigit('2')">2</span>
<span id="key3" onClick="AddDigit('3')">3</span>
<span id="key4" onClick="AddDigit('4')">4</span>
<span id="key5" onClick="AddDigit('5')">5</span>
<span id="key6" onClick="AddDigit('6')">6</span>
<span id="key7" onClick="AddDigit('7')">7</span>
<span id="key8" onClick="AddDigit('8')">8</span>
<span id="key9" onClick="AddDigit('9')">9</span>
<span id="key0" onClick="AddDigit('0')" style="width: 200px;">0</span>
<span id="keyback" class="clear" onClick="RemoveDigit()"> <div class="num_xBox">X</div></span>
</div>
</div>
</form>
关于javascript - 对于 MM/DD/YYYY 文本,仅显示用户未输入的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40931580/
我需要使用正则表达式验证格式为 dd/mm/yyyy 的日期字符串。 此正则表达式验证 dd/mm/yyyy,但不验证 31/02/4500 等无效日期: ^(0?[1-9]|[12][0-9]|3[
我需要检查给定字符串的日期。我得到的字符串不规则,我不想使用 Dateformat 或类似的东西。我试图避免出现多个异常。我需要 dd.MM.yyyy 和 MM.yyyy 和 yyyy 的正则表达式。
我想使用在这里找到的 jQuery 屏蔽输入插件 http://digitalbush.com/projects/masked-input-plugin/格式化日期。 我正在从数据库中提取数据以在页面
我正在尝试以更有效的方式根据当前日期找出当前财政年度(FY - 3 月至 4 月)。这是我到目前为止写的内容 public static void main(String[] args) {
我已经搜索了该网站,但没有找到接近我需要的答案。基本上我的日期正确显示为“2013-05-09”,但我想要的是“2013 年 3 月 19 日”或使其更好“3 月 19 日, 2013 年”。 请向我
我需要使用 C# 更改日期字符串的格式 来自:“06/16/2010”或“16/06/2010” 至:“2010-06-16” 你能帮我实现这个吗 谢谢 最佳答案 如果您已经将它作为 DateTime
我正在以 MMM-yyyy 格式从 View 中提交日期值,即“Apr-2019”作为字符串。我需要将字符串值转换为 .Net 支持的日期格式,如 dd-MM-yyyy 或 yyyy-MM-dd。这里
我有一个包含以下数据的平面文件 2/12/2016 2/3/2017 12/23/2017 04/23/2017 第一个是 M/dd/yyyy,第二个是 M/d/yyyy,其余日期格式为 MM/dd/
好吧,我已经和这个战斗了足够长的时间。我有一个正则表达式 ^(1[0-2]|0[1-9]|\d)\/(20\d{2}|19\d{2}|0(?!0)\d|[1-9]\d) 这将匹配 8/15、08/15
这个问题在这里已经有了答案: 关闭 10 年前。 Possible Duplicate: Extending JavaScript's Date.parse to allow for DD/MM/Y
我有 json 对象列表,其中一个字段是日期。问题是日期在 json 中以不同的方式写入。 大多数看起来像: "publishedDate": "2005-01-28" "publishedDat
这个问题已经有答案了: Generate & parse "Year-Month" values in text from Java (1 个回答) 已关闭 7 年前。 我有一个变量: YearMon
我对日期格式有一个奇怪的问题。就像,我正在使用 jquery 日期选择器,它设置为格式 dd/mm/yy。因此,当我在该字段中填写 01/09/2015 时,它应该意味着日期是 2015 年 9 月
我有以下日期, 24/04/2019 13/05/2019 12/04/2019 我想删除年份并将这些日期转换为以下格式, 24/04 13/05 12/04 这不是仅用于输出我想在该日期执行加法或申
“YYYY”和“yyyy”之间的确切区别是什么。我读过 this link ,它指出 A common mistake is to use YYYY. yyyy specifies the calen
我有一个日期列,其中日期格式为 2010-04-14 在 SQL Server 中。有没有办法将日期格式检索为 14/04/2010 在选择语句中? 最佳答案 试试这个: SELECT CONVERT
我有这个正则表达式:(\d{4})\/(\d{2,4})\/?(\w{2})?这似乎工作正常,但我想避免以下情况,例如:我有一个字符串“2020/2000/WEEEE”并且它匹配它。 它匹配的其他错误
这是用户输入日期的代码:(它必须是我的日期选择器,但表单必须将日期字段作为文本提交 - 不要问) 提交时,我在 javascript 中调用验证逻辑。我附上了当我尝试输入 01/01/2001 作为用
我正在尝试以 YYYY-YY 格式提取会计日期字符串的最后一年 (YY)。例如,这个“1999-00”的最后一年是 2000 年。 当前代码似乎涵盖了除此之外的大多数情况。 import pandas
这个问题已经有答案了: 已关闭11 年前。 Possible Duplicate: Conversion of Date 我从对话框中获取的日期为:5-1-2012 - 作为字符串。 我需要将其转换为
我是一名优秀的程序员,十分优秀!