Rails文本区域在Internet Explorer

时间:2016-09-19 03:38:30

标签: ruby-on-rails internet-explorer-11

我不确定这是怎么回事,但占位符似乎是在文本区域中放入内容而不是Internet Explorer v11中的占位符

Internet Explorer v11

ie_screenshot

chrome_screenshot

这是rails文本区号

= f.text_area :qhse_rules_comment, class: 'form-control audit_area', rows: '2', placeholder: t('.please_enter_comments')

如何使Internet Explorer不将占位符用作文本区域内容?

2 个答案:

答案 0 :(得分:0)

是IE有这个问题。

您可以使用gem' jquery-placeholder-rails'解决这个问题

https://github.com/navinpeiris/jquery-placeholder-rails

答案 1 :(得分:0)

这是一个已知的IE错误,它被跟踪here。使用JS解决方法将是您最好的解决方案,例如

/**
 * Returns a "bug free" html string from a jQuery element. Takes care of an IE (>=10) bug which occurs when a textarea has a placeholder attribute.
 *
 * The problem is when a textarea in IE (>=10) has a placeholder attribute, IE also adds the value of this attribute as text/value to the textarea.
 * Which means that .html() of such an element returns something like <textarea placeholder="foo">foo</textarea> (but should be <textarea placeholder="foo"></textarea>),
 * therefore $($target.html()) would return a textarea which now has value (which is the placeholder)!
 */


var tidyHtml = function($target) {
    var cleanHtml = $target.html(), // variable now contains "buggy" textareas
        badIndizes = [];

    $target.find('textarea[placeholder]').each(function(index, element) {
        if($(element).text() !== $(element).val()) { // there is something in .text(), but no value exists! IE bug! (do NOT use .html() here, because it's escaped -> val() is not escaped)
            badIndizes.push(index);
        }
    });

    if(badIndizes.length > 0) {
        cleanHtml = $(cleanHtml).find('textarea[placeholder]').filter(function(index) {
            return $.inArray(index, badIndizes) > -1;
        }).html('').parents().last().wrap('<p>').parent().html();
    }

    return cleanHtml;
};
信用 - jamez1414