【问题标题】:How to make a Ajax Submit Button with an html tag inside the label如何在标签内制作带有 html 标记的 Ajax 提交按钮
【发布时间】:2016-09-22 16:48:05
【问题描述】:

我想在 ajaxsubmitbutton 中添加 fontawesome 图标,

<?php echo CHtml::ajaxSubmitButton('<i class="fa fa-plus"></i> Print Preview',
array('ma/select'),
array(  'success'=>'reloadGrid',
        'error'=>'js:function(data){
            alert("Please select checkbox");
            return false;
        }'),
array(  //'encodeLabel'=>false,
        'class'=>'btn btn-success',
        )); ?>


我尝试将encodeLabel 设置为false,并尝试将encode 设置为false,所有这些都不起作用,
有人知道该怎么做吗?谢谢

【问题讨论】:

    标签: html ajax yii


    【解决方案1】:

    你为什么使用encodeLabel?问题是 FontAwesome 样式表使用 before 伪元素来添加图标。

    :after:before 伪元素,它们只能放在容器元素上。为什么?因为它们附加在该特定元素内。 input 不是容器。 button 例如 is 因此你可以穿上它们。

    echo CHtml::ajaxSubmitButton( '&#xf067; Print Preview ', $url, array(),
     array('encode'=>false)
    )
    

    在 CSS 中是这样的:

    input[type="submit"] {
      font-family: FontAwesome, 'Ubuntu', sans-serif;
    }
    

    如需进一步参考,请查看: How do I add a Font Awesome icon to input field?

    【讨论】:

    • 我已经尝试过这个答案,但不适用于 ajaxsubmitbutton
    • 检查并尝试更新的答案,这将在input上生成一个很棒的字体图标
    猜你喜欢
    • 2013-01-12
    • 2019-10-17
    • 1970-01-01
    • 2011-11-12
    • 2012-10-27
    • 1970-01-01
    • 1970-01-01
    • 2016-06-17
    • 1970-01-01
    相关资源
    最近更新 更多