placeholder is not working in IE9

后端 未结 3 1354
栀梦
栀梦 2021-01-15 04:41

I am salesforce (SFDC) developer. In my visualforce page for input box I am using placeholder code.

3条回答
  •  孤城傲影
    2021-01-15 05:35

    A little simpler answer worked for me not being very trusting of Regex (my downfall)

    function setPlaceHolderForIE9() {
        var pos = window.navigator.userAgent.indexOf("MSIE");
    
        if (pos > 0) {
            if (window.navigator.userAgent.substring(pos + 5, window.navigator.userAgent.indexOf(".", pos)) < 10) {
                //alert($("input[placeholder]").val($("input[placeholder]").attr("placeholder")));
                $("input[placeholder]").each(function () {
                    $(this).val($(this).attr("placeholder"));
                });
    
                $("input[placeholder]").click(function () {
                    if ($(this).val() === $(this).attr("placeholder")) {
                        $(this).val('');
                    }
                });
    
                $('input[placeholder]').blur(function () {
    
                    if ($.trim($(this).val()).length === 0) {
                        $(this).val($(this).attr("placeholder"));
                    }
                });
    
    
            }
        }
    }
    

提交回复
热议问题