【问题标题】:How to add CSS to this PHP statement?如何在这个 PHP 语句中添加 CSS?
【发布时间】:2013-04-09 00:48:35
【问题描述】:

如何添加这个 css:

<div class="alert alert-error">
</div>

到这个 PHP 代码:

<?php echo this->element->error; ?>

它们是“this”堆栈旁边的“$”,不会显示它

我需要它只在它处于活动状态时才显示。我试过这样做:

<?php if ($element->error != '') :?>
<div class="alert alert-error"> 
<?php echo $element->error?>
</div>
<?php endif;?>

但它不起作用

错误图片如下: http://i.imgur.com/EFtdjE5.png

【问题讨论】:

  • 您的意思是在 if/echo 语句中使用 $this-&gt;element&gt;error 吗?
  • But it doesn't work 你能说得更具体点吗? &lt;?php echo $element-&gt;error?&gt; 缺少 ;

标签: php css twitter-bootstrap joomla


【解决方案1】:

尝试使用isset 创建 if else 条件

  // if `$this->element->error` is TRUE or SET..
 <?php if(isset($this->element->error)){?>
    <div class="alert alert-error"> 
    <?php echo $this->$element->error;?>
    </div>
    <?php }?>
 // if not it will be just ignored

【讨论】:

  • 好的,在你的第二个 php 语句前添加 $this 给了我这个:i.imgur.com/IUmbSJN.png
  • 现在我只需要隐藏空警报框,其余的非错误
  • @NickN 你应该在你的声明中包含 alertbox div
  • 这是我的主要目标,只是不知道具体如何
  • 你能解释清楚一点吗? :D ,如果没有显示错误,你想要做的是删除另一个空警报框吗?
【解决方案2】:
<?php if ($this->element->error != '') :?>
    <div class="alert alert-error"><?php echo $this->element->error;?></div>
<?php endif;?>

这行得通。请注意我的代码与问题的区别。感谢@Kaii 的所有时间。

【讨论】:

  • 两个地方的$this和一个";"
猜你喜欢
  • 2013-05-11
  • 2018-02-19
  • 2012-10-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-08-13
相关资源
最近更新 更多