placeholder is not working in IE9

后端 未结 3 1417
栀梦
栀梦 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

    As IE9 doesn't support the placeholder attribute, you can do it in Javascript/jQuery like so (quickly written, not tested):

    if(navigator.appVersion.match(/MSIE [\d.]+/)){
        var placeholderText = 'Some Placeholder Text';
        $('#first_name').val(placeholderText);
        $('#first_name').blur(function(){
            $(this).val() == '' ? $(this).val(placeholderText) : false;
        });
        $('#first_name').focus(function(){
            $(this).val() == placeholderText ? $(this).val('') : false;
        });
    }
    

    Do the same for the blur event too, then that will mimic a placeholder attribute.

    [Edit]

    Okay, after rethinking this (due to the comment) this is really not the most elegant solution (however it does work), so I would disregard this answer totally.

提交回复
热议问题