admin管理员组

文章数量:1401509

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;">

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.

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;">

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.

Share Improve this question edited Feb 27, 2012 at 13:48 Octavian Helm 39.6k19 gold badges99 silver badges102 bronze badges asked Feb 27, 2012 at 13:30 user886596user886596 2,4405 gold badges37 silver badges54 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 4

Take a look at this fiddle: http://jsfiddle/tuliomonteazul/EGUcj/

To fix the default value when the page loads I just mented the last call of checkVal();. And to fix the onblur to apply the default value too, I mented 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.

本文标签: javascriptMasked Input Plugin with a default valueStack Overflow