首页 > 其他分享 >解决IE浏览器textarea标签placeholder不生效的问题

解决IE浏览器textarea标签placeholder不生效的问题

时间:2024-01-25 15:12:14浏览次数:15  
标签:style 浏览器 textarea placeholder value element document IE

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

相关文章

  • A Format Compliant Encryption Method for 3D Objects Allowing Hierarchical Decryp
    Abstract—Withtheincreasingpopularityof3Dobjectsinindustryandeverydaylife,3Dobjectsecurityhasbecomeessential.Whilethereexistsmethodsfor3Dselectiveencryption,whereaclear3Dobjectisencryptedsothattheresulthasthedesiredl......
  • client-go令牌桶限流配置
    funcaddListWatchCfgAndClient(){ cfg,err:=clientcmd.BuildConfigFromFlags("","/root/.kube/config") iferr!=nil{ klog.Fatalf("Errorbuildingkubeconfig:%s",err.Error()) } cfg.QPS=5 cfg.Burst=10 kubeClient......
  • CodeForces 1667E Centroid Probabilities
    洛谷传送门CF传送门首先需要了解重心的三种定义:删掉一个点后剩下子树大小\(\le\frac{n}{2}\)的点\(\sum\limits_{i=1}^n\text{dis}(u,i)\)最小的点最深的\(sz_u\ge\left\lceil\frac{n}{2}\right\rceil\)的点这道题我们使用第三种定义,也就是要统计\(i\)为最......
  • 2024AAAI_SGNet Structure Guided Network via Gradient-Frequency Awareness for Dep
    1.任务描述: 给定输入LR深度图和HRRGB图像,引导DSR目的是在ground-truth深度图监督的条件下,预测HR深度图2.Network本文提出的SGNet主要包括两部分,即梯度校准模块(GCM)和频率感知模块(FAM)。首先将RGB图像和上采样后的LR深度图送入到GCM,利用RGB丰富的梯度信息在梯度域中......
  • Supplier 惰性调用和 Future#get 同步等待调用结合
    ......
  • Permission denied: user=hive, access=EXECUTE, inode=“/tmp“:root:supergroup:drw
    在执行Hadoop的创建目录、写数据等情况,可能会出现该异常,而在读文件的时候却不会报错,这主要是由于系统的用户名不同导致的,由于我们进行实际开发的时候都是用Windows操作系统,而编译后的JAVA程序是部署在Linux上的。而Windows的用户名一般都是自定义的或者是administrator,Linux的用户......
  • G. Mischievous Shooter
    G.MischievousShooterOncethemischievousandwaywardshooternamedShelfoundhimselfonarectangularfieldofsize$n\timesm$,dividedintounitsquares.Eachcelleithercontainsatargetornot.Shelonlyhadaluckyshotgunwithhim,withwhich......
  • openGauss学习笔记-206 openGauss 数据库运维-常见故障定位案例-too many clients alr
    openGauss学习笔记-206openGauss数据库运维-常见故障定位案例-toomanyclientsalready206.1高并发报错“toomanyclientsalready”或无法创建线程206.1.1问题现象高并发执行SQL,报错“sorry,toomanyclientsalready”;或报无法创建线程、无法fork进程等错误。206.1.2......
  • js 旧 IE 中的 innerHTML
    在所有现代浏览器中,通过innerHTML插入的<script>标签是不会执行的。而在IE8及之前的版本中,只要这样插入的<script>元素指定了defer属性,且<script>之前是“受控元素”(scopedelement),那就是可以执行的。<script>元素与<style>或注释一样,都是“非受控元素”(NoScopeelement)......
  • 共话 AI for Science | 北京大学王超名:BrainPy,迈向数字化大脑的计算基础设施
    导读:2023和鲸社区年度科研闭门会以“对话AIforScience先行者,如何抓住科研范式新机遇”为主题,邀请了多个领域的专家学者共同探讨人工智能在各自领域的发展现状与未来趋势。在脑科学领域,数字化大脑通过数学模型和计算机仿真对大脑进行精确的建模和重构,可以更好地理解和探索大脑......