【问题标题】:Changing CSS styles with PHP and jQuery使用 PHP 和 jQuery 更改 CSS 样式
【发布时间】:2012-12-27 13:08:06
【问题描述】:

我正在执行 PHP if/else 语句。

但是,我希望代码执行以下操作:

<?php 

    if ($condition == true){ 
       echo 'ITS TRUE!'; 
    }else { 
       #id-element.css('display':'none'); 
    } 

?>

请注意,ELSE 语句执行的 jQuery 行会更改相关元素的 css 样式。

我该怎么做?

有人对我如何实现 PHP if/else 并在 PHP if/else 语句中使用 jQuery 更改 css 样式有任何建议/示例吗?

【问题讨论】:

  • 你可以在页面头部的&lt;style&gt;标签内输出CSS——那么就不需要jQuery了

标签: php javascript jquery html css


【解决方案1】:

您可以为样式元素回显 HTML 并将 CSS 放入其中。

else {
    echo '<style type="text/css">
        #id-element {
            display: none;
        }
        </style>';
}

【讨论】:

  • 这对我有用,谢谢。
【解决方案2】:

估计你可以这样做:

<?php
    if ($condition == true): 
         echo 'ITS TRUE!'; 
    else: 
?> 
    //put whatever html/style/script you want here, for example
    <script>
        $( '#id-element' ).css('display', 'none');
    </script>
<?php endif; ?>

【讨论】:

    猜你喜欢
    • 2013-07-20
    • 2010-10-06
    • 1970-01-01
    • 2017-07-14
    • 1970-01-01
    • 2016-06-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多