Posts Tagged ‘placeholder’

25 05 2011

placeholder

bigCat Posted in JavaScript - 42 Comments
function placeholderSupport(){\r\nvar inp = document.createElement('input');\r\nreturn 'placeholder' in inp;\r\n}\r\nif(!placeholderSupport()){\r\nvar inputId = document.getElementById('inputID');\r\nvar placeholderWords = 'plz write sth.';\r\ninputId.setAttribute('value',placeholderWords);\r\ninputId.className = 'inp_txt inp_nofocus';\r\ninputId.onfocus = (function(){\r\nif(this.value === placeholderWords){\r\nthis.value = '';\r\n}\r\n});\r\ninputId.onblur = (function(){\r\nif(this.value === ''){\r\nthis.value = placeholderWords;\r\n}\r\n});\r\n}
Host: (miao) | Word: Press | Code: HTML5