Skip to content

Instantly share code, notes, and snippets.

@pylemon
Forked from aaronsnoswell/gist:3786176
Last active August 29, 2015 13:57
Show Gist options
  • Save pylemon/9542716 to your computer and use it in GitHub Desktop.
Save pylemon/9542716 to your computer and use it in GitHub Desktop.
让html5 number 字段显示的 placeholder 可以为非数字
// 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