我有以下要求,在表格的时间字段中,如果不是以这种格式手动键,则应自动添加冒号hh:mm:ss
我有下面的代码,它适用于自动填充,但如果用户键冒号手动它添加两个冒号像hh :: m:ss
有人可以帮助解决这个问题吗?
JSP:
<b:form-group label="${runtime}" labelFor="runtime" cssLabel="col-sm-2" cssBody="col-sm-2" cssClass="required">
<form:input path="runTime" cssClass="form-control" required="required" maxlength="8"/>
<form:errors path="runTime" cssClass="validate-error"/>
</b:form-group>
Run Code Online (Sandbox Code Playgroud)
JS:
$('#runTime').on('keydown', function(e) {
if(e.keyCode != 8 && (this.value.length === 2 || this.value.length === 5)) {
this.value += ":";
}
});
Run Code Online (Sandbox Code Playgroud)
更新答案
我们必须在使用chiliNUT回答崩溃之前添加额外的检查,否则选择所有并且点击删除/退格按钮在Chrome浏览器中不起作用.
$('#runTime').on('keydown', function(e) {
//your code
if(e.keyCode != 8 && (this.value.length === 2 || this.value.length === 5)) {
this.value += ":";
}
//collapse double colons
if(this.value.endsWith("::")) {
this.value=this.value.replace(/:+/g,":");
}
});
Run Code Online (Sandbox Code Playgroud) 有人用Spring 4.2实现了EhCache 3(不使用Spring启动).如果是这样,实施该步骤的步骤是什么?
问题是spring-context-support(添加Spring的缓存注释)要求Ehcache的CacheManager在这个类路径上:net.sf.ehcache.CacheManager
但是,在Ehcache 3中,CacheManager类驻留在另一个类路径上:org.ehcache.CacheManager.
所以,基本上spring-context-support不支持Ehcache 3.你必须直接使用JSR-107注释,而不是Spring提供的注释.
如果有人实现了这个组合,请给你ehcache.xml和spring配置以供参考.