IE10给textarea设置了placeholder,F12控制台打印document.getElementById(id).getAttribute('placeholder'),可以看到placeholder的值,但是浏览器不显示,可以再添加如下代码显示出来,不需要引用JQuery,前提是该元素已经设置了placeholder属性,并且浏览器支持placeholder,IE8和IE9不支持,参考链接https://www.zhangxinxu.com/wordpress/2012/02/html5-placeholder%E4%BD%BF%E7%94%A8%E7%BB%8F%E9%AA%8C%E5%88%86%E4%BA%AB%E5%8F%8A%E6%8B%93%E5%B1%95/
!("placeholder" in document.createElement("input"))用来判断浏览器是否支持placeholder
function placeholderForIE (element) { var placeholder = ''; if (element && !("placeholder" in document.createElement("input")) && (placeholder = element.getAttribute("placeholder"))) { element.onfocus = function() { if (this.value === placeholder) { this.value = ""; } this.style.color = ''; }; element.onblur = function() { if (this.value === "") { this.value = placeholder; this.style.color = 'graytext'; } }; //样式初始化 if (element.value === "") { element.value = placeholder; element.style.color = 'graytext'; } } };
placeholderForIE(document.getElementById(id))//调用上面的函数,前提是该元素已经设置了placeholder属性
标签:style,浏览器,textarea,placeholder,value,element,document,IE From: https://www.cnblogs.com/yusl/p/17987206