【问题标题】:New line inside textarea placeholder via jQuery通过jQuery在textarea占位符内换行
【发布时间】:2015-04-14 17:40:06
【问题描述】:

我想通过 jQuery 在 textarea 中放置一个占位符,但它在 Firefox 中不起作用。

下面是我的代码:

jQuery('#orderlink_bulk').attr("placeholder","ssss /n sss");

我该怎么做?

【问题讨论】:

    标签: javascript jquery html css firefox


    【解决方案1】:

    在这种情况下,escape string 的正确方法是使用\n 而不是/n

    jQuery('#orderlink_bulk').attr("placeholder","ssss \n sss");
    

    但它不适用于该线程中所说的 Firefox:

    Can you have multiline HTML5 placeholder text in a <textarea>?

    FIDDLE

    【讨论】:

      【解决方案2】:

      如果您尝试制作多行占位符,则不支持,如 W3C 文档中所述 http://www.w3.org/html/wg/drafts/html/master/forms.html#the-placeholder-attribute

      这在带有\n 的 Webkit 中运行良好,但在 FF 中无法运行 http://jsfiddle.net/kyqo9xh8/

      【讨论】:

        猜你喜欢
        • 2012-11-25
        • 2019-07-04
        • 2013-06-16
        • 2020-05-20
        • 1970-01-01
        • 2012-02-20
        • 2014-09-15
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多