【问题标题】:How to write html tag inside blade form object label..?如何在刀片表单对象标签内写入html标签..?
【发布时间】:2021-06-10 18:13:17
【问题描述】:

我必须写“Name * :”,其中 astrix 将是红色的。 我正在创建标签为:

    {!! Form::label("name","Name".<span class="red">*</span>." :") !!}

但这会导致:Name with html tag span tag。

谢谢

【问题讨论】:

标签: php laravel


【解决方案1】:

为此,您必须传递array。如下所示:

{!! Form::label("name", "Name:", array('class' => 'require') !!}

并在下面设置这个require 类的样式。希望这应该有效。

.require:after{ 
    content:'*'; 
    color:red; 
}

另一种方式,已更新:

我想,这就是你要找的。在span 中使用双引号,在style 中使用单引号。

{!! Form::label('name', 'Name:'),"<span style='color:red'>*</span>" !!}

这应该可行。

【讨论】:

  • @gaurav 看到这个更新的答案。这是你要找的。谢谢 :)
【解决方案2】:

使用这个:

label.required:after {
  color: red;
  content: "* :";
}

 {!! Form::label("name","Name", array('class' => 'required')) !!}

【讨论】:

  • 但这也会使冒号变成红色,我只想要红色的 *
【解决方案3】:

使用array 作为第三个参数:

{!! Form::label("name", "Name", array('class' => 'redast')) !!}

CSS 将是:

.redast{
    color: #000000;
}    

.redast:after{
    color: #FF0000;
    content: '*'; 
}

http://www.w3schools.com/cssref/pr_gen_content.asp

另外,为什么不使用这样的东西:

<div>
    <span>{!! Form::label("name", "Name") !!}</span>
    <span style="color:red;">&nbsp;*</span>
    <span>&nbsp;:</span>
</div>

【讨论】:

  • 我必须用红色写 *,你的代码会使“名称”变成红色。
  • 像这个:名字 * : * 会是红色的
  • 请尝试我更新的代码,让我知道它是否适合您。
  • 您的代码工作正常,但我需要在 * 之后使用“:”。它是黑色的。
  • 请检查跨度的替代方案,它肯定会按您的预期工作。
【解决方案4】:

您可以使用 css 样式添加 astrix,也可以创建自己的宏来显示您需要的任何内容:

Form::macro('myCustomLabel', function($inputName){

    return "<label for='$inputName'>Name<span class="red">*</span></label>";
});

查看这个链接,很有帮助:http://laravel-recipes.com/recipes/173/creating-form-macros

问候!

【讨论】:

    【解决方案5】:

    不要使用任何逗号,只需像这样在名称或标签后附加跨度即可。

       {!! Form::label("name","Name <span class='red'>*</span> :") !!}
    

    【讨论】:

      猜你喜欢
      • 2019-01-09
      • 2016-08-24
      • 1970-01-01
      • 2014-08-22
      • 1970-01-01
      • 1970-01-01
      • 2012-01-15
      • 2018-07-31
      • 1970-01-01
      相关资源
      最近更新 更多