首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何在IE8和9中支持占位符属性

如何在IE8和9中支持占位符属性
EN

Stack Overflow用户
提问于 2013-02-22 17:30:03
回答 9查看 239.8K关注 0票数 132

我有一个小问题,IE 8-9不支持输入框的placeholder属性。

在我的项目(ASP.NET)中提供这种支持的最好方法是什么?我正在使用jQuery。我需要使用一些其他的外部工具吗?

http://www.hagenburger.net/BLOG/HTML5-Input-Placeholder-Fix-With-jQuery.html是一个好的解决方案吗?

EN

回答 9

Stack Overflow用户

回答已采纳

发布于 2013-02-22 17:32:33

您可以使用这个jQuery插件:https://github.com/mathiasbynens/jquery-placeholder

但是你的链接似乎也是一个很好的解决方案。

票数 89
EN

Stack Overflow用户

发布于 2014-11-20 11:04:05

我有几个插件的兼容性问题,对我来说,这似乎是支持文本输入占位符的最简单方法:

代码语言:javascript
复制
function placeholders(){
    //On Focus
    $(":text").focus(function(){
        //Check to see if the user has modified the input, if not then remove the placeholder text
        if($(this).val() == $(this).attr("placeholder")){
            $(this).val("");
        }
    });

    //On Blur
    $(":text").blur(function(){
        //Check to see if the use has modified the input, if not then populate the placeholder back into the input
        if( $(this).val() == ""){
            $(this).val($(this).attr("placeholder"));
        }
    });
}
票数 3
EN

Stack Overflow用户

发布于 2013-12-10 19:22:47

代码语言:javascript
复制
$(function(){    
    if($.browser.msie && $.browser.version <= 9){
        $("[placeholder]").focus(function(){
            if($(this).val()==$(this).attr("placeholder")) $(this).val("");
        }).blur(function(){
            if($(this).val()=="") $(this).val($(this).attr("placeholder"));
        }).blur();

        $("[placeholder]").parents("form").submit(function() {
            $(this).find('[placeholder]').each(function() {
                if ($(this).val() == $(this).attr("placeholder")) {
                    $(this).val("");
                }
            })
        });
    }
});

尝尝这个

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15020826

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档