Placeholder not working for Internet Explorer

后端 未结 7 1499
青春惊慌失措
青春惊慌失措 2020-12-02 13:47

Placeholder for my textbox in below format is not working for Internet Explorer. Is there anyway to display placeholder for TextBox in Internet Explorer?

7条回答
  •  旧巷少年郎
    2020-12-02 14:17

    I have had this issue recently - I use modernizr to detect html5 features and then run a bit of js for the browsers that can't cope:

        function addPlaceHolder(input) {//using modernizr add placeholder text for non html5 users
        if (!Modernizr.input.placeholder) { 
            input.focus(function () {
                if (input.val() == input.attr('placeholder')) {
                    input.val('');
                    input.removeClass('placeholder');
                }
            }).blur(function () {
                if (input.val() == '' || input.val() == input.attr('placeholder')) {
                    input.addClass('placeholder');
                    input.val(input.attr('placeholder'));
                }
            }).blur();
            $(input).parents('form').submit(function () {
                $(this).find(input).each(function () {
                    if (input.val() == input.attr('placeholder')) {
                        input.val('');
                    }
                })
            });
        }
    }
    
    addPlaceHolder($('#Myinput'));
    

    seems to work well for me!

提交回复
热议问题