【问题标题】:how to place formatted code in a placeholder in an html如何将格式化代码放在html中的占位符中
【发布时间】:2019-12-29 20:55:13
【问题描述】:

我想在我的 html 占位符中有一段格式化的代码/json。
我希望占位符的格式与我在 html 中的格式相同。

   <textarea rows="9" data-bind="textInput: someVariable" 
     class="form-control" 
     placeholder=
        'e.g.
        {
            "type": "service_type",
            "project_id": "test-237012",        
            "client_email": "test@test-237012.gserviceaccount.com",
            "client_id": "111390682349634407434",
            ....
        }'>   
    </textarea> 

如何?

【问题讨论】:

  • 我检查了你的代码。它在 Firefox 中对我有用。你的占位符有什么问题?

标签: javascript html css placeholder pre


【解决方案1】:

您可能还需要添加cols 属性。见下文。

<textarea rows="10" cols="50" placeholder='e.g.
    {
        "type": "service_type",
        "project_id": "test-237012",        
        "client_email": "test@test-237012.gserviceaccount.com",
        "client_id": "111390682349634407434",
        ....
    }'></textarea>

【讨论】:

    【解决方案2】:

    重要的部分是在开始和结束标记之间不要有任何空格(空格、制表符、换行符)。任何空格都会阻止占位符出现。

    <textarea
      attribute1="value1"
      attribute2="value2"
      ...
    ></textarea>
    

    当占位符文本被截断时,您可以使用 colsrows 属性或使用 heightwidth 属性为文本区域定义 CSS 样式。

    【讨论】:

      猜你喜欢
      • 2012-02-25
      • 1970-01-01
      • 1970-01-01
      • 2019-11-20
      • 2018-09-22
      • 2016-07-11
      • 2014-06-23
      • 2018-10-25
      • 2015-10-21
      相关资源
      最近更新 更多