IE8兼容textarea的placeholder属性

news/2024/7/3 12:16:38

placeholder属性树html5提出的新属性,作用是为input框或textarea框添加初始提示内容。当控件获取焦点输入时,清空提示内容。但IE8及其以下的版本并不支持该属性的显示。

下面做如下处理:

 

 
  1. $(function(){

  2. if( !('placeholder' in document.createElement('input')) ){

  3. $('input[placeholder],textarea[placeholder]').each(function(){

  4. var that = $(this),

  5. text= that.attr('placeholder');

  6. if(that.val()===""){

  7. that.val(text).addClass('placeholder');

  8. }

  9. that.focus(function(){

  10. if(that.val()===text){

  11. that.val("").removeClass('placeholder');

  12. }

  13. })

  14. .blur(function(){

  15. if(that.val()===""){

  16. that.val(text).addClass('placeholder');

  17. }

  18. })

  19. .closest('form').submit(function(){

  20. if(that.val() === text){

  21. that.val('');

  22. }

  23. });

  24. });

  25. }

  26. });

第一个if条件是判断placeholder是否存在于解析的input框中。

closest方法的作用是:从当前元素开始向上查找,直到找到匹配的元素为止。

上诉closest方式计算查找form元素,然后在执行提交的form表单的时候执行sumit的方法。

 

上面添加了一个palceholder样式,其样式内容为:

 

 
  1. .placeholder{

  2. opacity:0.5;

  3. filter:alpha(opacity=50);

  4. }

opcaity属性是用来定义透明度的,其值在0-1.0之间。但IE8及其以下的版本并不支持。

在IE8上需用filter:alpha(opacity=?)来过滤,opacity的值在0-100间。

 

转载地址:https://blog.csdn.net/mafan121/article/details/47779411


http://www.niftyadmin.cn/n/3648188.html

相关文章

安全体系(二)——RSA算法详解

正文 本文主要讲述RSA算法使用的基本数学知识、秘钥的计算过程以及加密和解密的过程。 安全体系(零)—— 加解密算法、消息摘要、消息认证技术、数字签名与公钥证书 安全体系(一)—— DES算法详解 安全体系(三&#xf…

如何在Ubuntu 18.04上安装R [快速入门]

介绍 (Introduction) R is an open-source programming language that specializes in statistical computing and graphics. In this tutorial, we will install R on an Ubuntu 18.04 server. R是一种开源编程语言,专门研究统计计算和图形。 在本教程中&#xff0…

Google未来半年内的杀手锏预测

Google未来半年内的杀手锏预测郑昀 20060925麦田提出了他的预测《:大胆猜测google中国未来半年的“杀手锏”--麦田的读书生活》。我的基本观点如下:1: google ig没戏,除非上来就有大量信息可供选择; 2: 社区搜索是必定要做的; 3: …

Web2.0的大格局与高壁垒

郑昀 观点 20060927昨天千橡陈一舟针对裁人痛定思痛说:“一定要做大事,做适合大公司做的事情。大事情指超过30-40% 互联网用户都需要的产品,大事情能够撑得起上市公司 ,能支撑好几家上市公司。小事情指不超过5%互联网用户需要的产…

Node.js应用实战和工作原理解析

Node.js是一个基于Chrome JavaScript运行时建立的开发平台, 用于方便地搭建响应速度快、易于扩展的网络应用。Node.js 使用事件驱动,非阻塞I/O模型而得以轻量和高效,非常适合在分布式设备上运行数据密集型的实时应用,例如移动应用…

ubuntu16.04挂载_如何在Ubuntu 20.04上设置NFS挂载

ubuntu16.04挂载介绍 (Introduction) NFS, or Network File System, is a distributed file system protocol that allows you to mount remote directories on your server. This lets you manage storage space in a different location and write to that space from multip…

郑昀邀请开发(PHP/ASP.NET/C#/Java/C++)人才加盟etone[工作地点:北京]

我的公司最近不断地扩充团队,无奈通过公开媒体的招聘启事收到的技术类人才偏少,只好在我的blog里吆喝吆喝:希望优秀的Web开发人员加盟!我是谁?点击这里了解一下。2005年度CSDN十大最热门BLog作者排名第一; …

如何在Ubuntu 20.04上安装MariaDB

介绍 (Introduction) MariaDB is an open-source relational database management system, commonly used as an alternative for MySQL as the database portion of the popular LAMP (Linux, Apache, MySQL, PHP/Python/Perl) stack. It is intended to be a drop-in replace…