javascript 带有默认值的屏蔽输入插件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9465832/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Masked Input Plugin with a default value
提问by user886596
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.
我一直在使用 digitalbush 的屏蔽输入插件,我想知道是否有任何方法可以为屏蔽字段添加默认值。
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;">
but after applying the masking via
但通过应用屏蔽后
<script type="text/javascript">
$(document).ready(function(){
$("#date").mask("99/99/9999", {placeholder:"#"});
});
</script>
The default value HTML no longer works.
默认值 HTML 不再有效。
回答by Tulio
Take a look at this fiddle: http://jsfiddle.net/tuliomonteazul/EGUcj/
看看这个小提琴:http: //jsfiddle.net/tuliomonteazul/EGUCj/
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.
为了在页面加载时修复默认值,我刚刚评论了checkVal();
. 为了修复 onblur 以应用默认值,我在checkVal();
里面 评论.bind('blur.mask')
并更改onblur
了输入的功能。
I think the plugin's license permits to change his code.
我认为插件的许可证允许更改他的代码。