devc++输入更快_更好的时间输入

news/2024/7/19 13:08:45 标签: java, python, js, javascript, php
devc++输入更快

devc++输入更快

一些历史(Some history)

Some time ago, Simon Willison published a "Better Date Input" javascript that accepts all kinds of user inputs and tries to figure out a date out of it. For example "2006-02-08", "today", "next Friday" and so on. It's really neat, the original blog posting is here and a demo is available. A rehash of the idea was made by Nathaniel Brown, adding a popup calendar and some other tweaks/features (talking about it and a demo).

不久前,西蒙·威利森( Simon Willison)发布了一种“更好的日期输入” JavaScript,该JavaScript接受所有类型的用户输入并试图从中找出日期。 例如“ 2006-02-08”,“今天”,“下一个星期五”等等。 真的很整洁,原始的博客发布在这里,并提供了一个演示。 纳撒尼尔·布朗( Nathaniel Brown)对这个想法进行了重新表述,增加了一个弹出日历和其他一些调整/功能(谈论它和一个演示)。

Thanks to Derek of Subtitle Designs, who pointed out this "neato" script to me (for the second time!), I got curious as to what is involved in hacking the script to work with time instead of dates.

感谢Subtitle Designs的Derek(第二次向我指出了这个“ neato”脚本),我对破解该脚本以解决时间而不是日期所涉及的内容感到好奇。

结果 (Result)

  • A demo - just type something time-like, like "9" or "1pm" or "12:34:56" or "1300"

    演示-只需输入类似时间的内容,例如“ 9”或“ 1pm”或“ 12:34:56”或“ 1300”

  • The javascript

    JavaScript

工作原理(只需10个简单步骤(或更少);)) (How it works (in 10 easy steps (or less) ;)))

  1. User-entered value is passed to magicTime().

    用户输入的值将传递给magicTime()

  2. magicTime() asks parseTimeString() to parse that string and to return a Date object.

    magicTime()要求parseTimeString()解析该字符串并返回Date对象。

  3. parseTimeString() loops through an array of objects, each having a regular expression, trying to match the entered text.

    parseTimeString()遍历对象数组,每个对象都有一个正则表达式,试图匹配输入的文本。

  4. Once a regexp match is found, a corresponding function is called to "translate" the match to a valid Date

    找到正则表达式匹配项后,将调用相应的函数以将匹配项“翻译”为有效Date

  5. The result Date is passed back to magicTime(), which calls the callback function getReadable() for any tweaking and formatting of the result before displaying it (default output is hh:mm:ss)

    结果Date被传递回magicTime() ,它在显示结果之前调用回调函数getReadable()进行结果的任何调整和格式化(默认输出为hh:mm:ss)

原始想法的改进 (Improvements of the original idea)

Apart from just processing time instead of dates, there are a few improvements to the original script.

除了只处理时间而不是日期以外,原始脚本还有一些改进。

  • Regexps examples and (unit?) testing. In the array of objects where the regexp rules are defines, I've added another property - an array of examples illustrating sample matches. The purpose is two fold - to quickly provide a help with a list of supported formats and also to have the ability to test the regexps semi-automatically. So then the function getExamples() is called, it produces a list of acceptable values. If the same function is called passing a TRUE parameter, these example values are actually parsed and the result of the parsing is returned. This allows to quickly test all the regexps. Click "help" and/or "run tests!" in the demo for an illustration.

    正则表达式示例和(单元?)测试。 在定义regexp规则的对象数组中,我添加了另一个属性-一系列示例样本匹配示例。 目的有两个:Swift提供所支持格式的帮助,并具有半自动测试正则表达式的能力。 因此,将调用函数getExamples() ,它会生成可接受值的列表。 如果调用传递TRUE参数的相同函数,则实际上将解析这些示例值,并返回解析结果。 这样可以快速测试所有正则表达式。 点击“帮助”和/或“运行测试!” 在演示中进行说明。

  • getReadable() - a function that formats the output is introduced, allowing the users of this script to customize it quickly without interfering with the main logic. In this function you can opt for dropping the seconds, or rounding to the next minute, or five minutes, or an hour, or anything that has to do with displaying the result of the successful parse.

    getReadable() -引入了一种格式化输出的函数,该脚本的用户可以快速自定义它,而不会干扰主逻辑。 在此功能中,您可以选择减少秒数,或舍入到下一分钟,五分钟或一个小时,或与显示成功的解析结果有关的任何操作。

  • Optional message area. The message area, placed under the text box is optional. There is now a try..catch to make sure no JS error occurs if it's missing.

    可选消息区域。 放置在文本框下方的消息区域是可选的。 现在有一个try..catch ,以确保如果缺少JS错误都不会发生。

如何使用脚本 (How to use the script)

It shouldn't be a problem to integrate this into your application. You need to:

将其集成到您的应用程序中应该不是问题。 你需要:

  1. Get the javascript

    获取JavaScript

  2. (optionally) Tweak getReadable() to match your needs. Remember that at this time all parsing work is done and you have a valid Date object which you only need to display to the user

    (可选)调整getReadable()以满足您的需求。 请记住,此时所有解析工作都已完成,并且您具有有效的Date对象,只需要向用户显示即可

  3. (optionally) Place a div to display messages, related to the text box (see the demo). Name it with id id-of-the-input-messages

    (可选)放置div以显示与文本框相关的消息(请参见演示)。 用id id-of-the-input -messages

  4. Call magicTime() when you think appropriate (like onblur), passing the input element (e.g. document.getElementById('id-of-the-input'), or just this, depending from where you call it)

    当您认为合适时(如onblur ),调用magicTime() ,传递输入元素(例如document.getElementById('id-of-the-input')或仅this元素,具体取决于调用位置)

反馈 (Feedback)

Any comments, bug reports or requests are welcome! Thanks!

欢迎任何评论,错误报告或要求! 谢谢!

Tell your friends about this post on Facebook and Twitter

在Facebook和Twitter上告诉您的朋友有关此帖子的信息

翻译自: https://www.phpied.com/javascript-time-input/

devc++输入更快


http://www.niftyadmin.cn/n/1306699.html

相关文章

mysql5.7 操作_MySQL 5.7 常用操作

1、登录,查询数据mysql -u root -pshow databases;use information_schema;show tables;desc TABLES;select * from TABLES;2、修改密码-- 登录后执行SET PASSWORD PASSWORD(newpassword);3、mysql根据配置文件会限制server接受的数据包大小。有时候大的插入和更新…

Java中用正则表达式判断日期格式是否正确

1、Java中用正则表达式判断日期格式是否正确 DateType.java: /*** Title:DateType.java* Package:com.you.dao* Description:* Author: 游海东* date: 2014年3月8日 下午10:54:50* Version V1.2.3*/ package com.you.dao;import java.util.regex.Matcher; import j…

看不见的广告

Launched TheInvisibleAd.com today. Its my version of the amazing Million Dollar Homepage and is mostly JavaScript muscle flexing 😉 There is a little PHP, but very little, some style work and some AJAX/XML. But most of it is the JavaScript. 今天…

Java中过滤出字母、数字和中文的正则表达式

1、Java中过滤出字母、数字和中文的正则表达式 (1)过滤出字母的正则表达式 [^(A-Za-z)] (2)过滤出数字的正则表达式 [^(0-9)] (3)过滤出中文的正则表达式 [^(\\u4e00-\\u9fa5)] (4)…

系统服务有多个mysql_windows系统中安装多个Mysql服务

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼第一步:安装Mysql(本人使用mysql-5.5.14-win32.msi)到任意目录 (D:\Program Files\MySQL , 此处记作 MYSQL_HOME ) ,第二步:在任意目录新建一文件夹(D:\Progra…

共同成长共同进步的团队_共同评论

共同成长共同进步的团队coComment looks like a very promising service. Helping you keep track of all comments you post on all various blogs ... sweet! coComment看起来是一项非常有前途的服务。 帮助您跟踪您在各种博客上发布的所有评论...太好了! Check i…

JavaScript过滤特殊字符

JavaScript过滤特殊字符 1、设计实例 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns"http://www.w3.org/1999/xhtml"> <head> &…

java 物理地址_java怎样取得网卡物理地址

展开全部给你一个局域32313133353236313431303231363533e58685e5aeb931333361323530网的聊天程序或许对你有用&#xff01;&#xff01;&#xff01;import java.net.*;import java.awt.*;import javax.swing.*;import java.awt.event.*;import java.util.GregorianCalendar;im…