让ie也兼容placeholder

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>让ie也兼容placeholder</title>
<style>
    input::-moz-placeholder{ color:#00f;}
    ::-webkit-input-placeholder{ color:#00f;}
</style>
<script src="../../js/jquery-1.7.2.js"></script>
<script>
$(function(){
    function placeHolder(wrapDom){
        var support=‘placeholder‘ in document.createElement(‘input‘);
            if(!support){
                var $pass=$("input[type=password]"),
                passL=$pass.length;
                if(passL){
                    $pass.hide().parent().append("<input type=‘text‘ value=‘请输入密码‘ class=‘pwdtext‘/>");
                    $(".pwdtext").focus(function(){
                        $(this).hide().prev("input").show().focus();
                    })
                }
                wrapDom.find(‘[placeholder]‘).focus(function() {
                    var input = $(this);
                    if(input.val() == input.attr(‘placeholder‘)) {
                        input.val(‘‘);
                    }                    
                }).blur(function() {
                    var input = $(this);
                    if(/^password/.test(input.attr("id"))){
                        if(!input.val()) {
                            input.hide().next("input").show();
                        }
                    }
                    if(input.val() == ‘‘ || input.val() == input.attr(‘placeholder‘)) {
                       input.val(input.attr(‘placeholder‘));
                    }
                }).blur();
            };
    }
    placeHolder($("#test"));    
})
</script>
</head>

<body>
<form action="" method="post" id="test">
    <input type="text" name="username" id="username"  placeholder="用户名" />
    <input type="password" name="password" id="password" placeholder="密码"/>
</form>
</body>
</html>

时间: 2024-07-29 06:39:19

让ie也兼容placeholder的相关文章

兼容placeholder

众所周知.IE9以下不兼容placeholder属性,因此自己定义了一个jQuery插件placeHolder.js.以下为placeHolder.js的代码: /** * 该控件兼容IE9下面,专门针对IE9下面不支持placeholder属性所做 * Author: quranjie * Date:2014-09-26 */ $(function() { // 假设不支持placeholder,用jQuery来完毕 if(!isSupportPlaceholder()) { // 遍历全部i

【jquery】基于 jquery 实现 ie 浏览器兼容 placeholder 效果

placeholder 是 html5 新增加的属性,主要提供一种提示(hint),用于描述输入域所期待的值.该提示会在输入字段为空时显示,并会在字段获得焦点时消失.placeholder 属性适用于以下类型的 input 标签:text, search, url, telephone, email 以及 password. 我们先看下在谷歌浏览器中的效果,如图所示: 获得焦点时: 输入字段: 因为是 html5 属性,自然低版本的浏览器比如 ie6-8 不兼容.下面就介绍下如何在低版本浏览器中

html5的placeholder属性(IE如何兼容placeholder属性)

界面UI推荐 jquery html5 实现placeholder兼容password  IE6 html5的placeholder属性(IE如何兼容placeholder属性) 2013-01-05 10:26:06|  分类: web学习 |  标签:html  js  ie  placeholder  |举报 |字号大中小 订阅 placeholder属性,IE对其的支持表示无奈,firefox.google chrome表示毫无压力. HTML5对Web Form做了许多增强,比如inp

IE8兼容placeholder的方案

用JavaScript解决Placeholder的IE8兼容问题 placeholder属性是HTML5新添加的属性,当input或者textarea设置了该属性后,该值的内容将作为灰色提示显示在文本框中,当文本框获得焦点时,提示文字消失,placeholder可作为输入框的提示文案 如图: placeholder是常用的属性,它使得input框内有很友好的提示效果.高版本浏览器都支持placeholder属性,但IE9以下版本的浏览器并不支持这一属性.这里用JavaScript实现添加对浏览器

【工作笔记五】html5的placeholder属性(IE如何兼容placeholder属性)

placeholder属性,IE对其的支持表示无奈,firefox.google chrome表示毫无压力. HTML5对Web Form做了许多增强,比如input新增的type类型.Form Validation等.Placeholder是HTML5新增的另一个属性,当input或者textarea设置了该属性后,该值的内容将作为灰字提示显示在文本框中,当文本框获得焦点时,提示文字消失.以前要实现这效果都是用JavaScript来控制才能实现: <input id="t1" 

低版本IE浏览器不兼容placeholder解决方法

虽说现在很多网站都放弃了IE浏览器的低版本,但是很多时候咱们还得看甲方的要求就制作网站.如果甲方要求兼容IE789,那么咱们就得给人家做出来兼容的产品. 今天就IE789的input标签的placeholder说一说解决方法. 一.优雅降级解决(极力推荐) 也就是俗称的不解决细节,只要大体能满足浏览的要求就可以,placeholder低版本不显示,那么咱们就不在去做兼容方法,反正以后的几年IE低版本的浏览器会被淘汰. 二.使用input的value制作placeholder的效果 这个是我以前用

【JS】IE兼容placeholder

直接上代码: $(document).ready(function () { var doc = document, textareas = doc.getElementsByTagName('textarea'), supportPlaceholder = 'placeholder' in doc.createElement('textarea'), placeholder = function (textarea) { var text = textarea.getAttribute('pl

ie上如何兼容placeholder

首先,判断浏览器是否支持placeholder属性: var input = document.createElement('input'); if("placeholder" in input){ alert('支持'); }else{ alert('不支持'); } (1)如果只需要让不支持placeholder的浏览器能够支持改功能,并不要求支持原生placeholder的浏览器表现一致,那么可以采用如下方法: Placeholder在不支持html5的低版本的浏览器中,plac

ie9以下浏览器不兼容placeholder的解决方案

html结构如下: <form action="post" class="xz-form" id="xz-form"> <div id="validate" class="xz-validate-tip"></div> <div class="xz-userName"> <input class="xz-inputName&