问题描述
我一直在使用digitalbush的掩码输入插件,我想知道是否您可以通过任何方式将默认值添加到被屏蔽的字段.
I've been using digitalbush's masked input plugin, and I was wondering if there was any way you could add a default value to the masked fields.
我尝试使用以下方式添加它:
I've tried adding it using:
<input id = "date" type="text" value="DD/MM/YYYY" onfocus="this.value = this.value=='DD/MM/YYYY'?'':this.value;" onblur="this.value = this.value==''?'DD/MM /YYYY':this.value;">
但是在通过
<script type="text/javascript">
$(document).ready(function(){
$("#date").mask("99/99/9999", {placeholder:"#"});
});
</script>
默认值HTML不再起作用.
The default value HTML no longer works.
推荐答案
看看这个小提琴: http://jsfiddle.net/tuliomonteazul/EGUcj/
要修复页面加载时的默认值,我只注释了checkVal();
的最后一次调用.为了修复onblur也要应用默认值,我在.bind('blur.mask')
内注释了checkVal();
并更改了输入的onblur
功能.
To fix the default value when the page loads I just commented the last call of checkVal();
.And to fix the onblur to apply the default value too, I commented the checkVal();
inside the .bind('blur.mask')
and changed the onblur
function of the input.
我认为该插件的许可证允许更改其代码.
I think the plugin's license permits to change his code.
这篇关于具有默认值的Masked Input插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!