用PHP和jQuery改变CSS样式

Changing CSS styles with PHP and jQuery

本文关键字:CSS 样式 改变 jQuery PHP      更新时间:2023-09-26

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

但是,我希望代码做这样的事情:

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

注意ELSE语句执行了一行jQuery,改变了相关元素的css样式。

我该怎么做呢?

任何人有任何建议/例子,我如何实现PHP if/else和改变css样式与jQuery内PHP if/else语句?

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

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

我想你可以这样做:

<?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; ?>