-
-
Save pylemon/9542716 to your computer and use it in GitHub Desktop.
让html5 number 字段显示的 placeholder 可以为非数字
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// jQuery version | |
$("input[type='number']").each(function(i, el) { | |
el.type = "text"; | |
el.onfocus = function(){this.type="number";}; | |
el.onblur = function(){this.type="text";}; | |
}); | |
// Stand-alone version | |
(function(){ var elms = document.querySelectorAll("input"), i=elms.length; | |
while(i--) { | |
var el=elms[i]; if(el.type=="number"]) | |
el.type="text", | |
el.onfocus = function(){this.type="number";}, | |
el.onblur = function(){this.type="text";}; | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment