[英]Changing CSS styles with PHP and jQuery
I'm executing a PHP if/else statement. 我正在执行PHP if / else语句。
However, I want the code to do something like this : 但是,我希望代码执行以下操作:
<?php
if ($condition == true){
echo 'ITS TRUE!';
}else {
#id-element.css('display':'none');
}
?>
Note that the ELSE statement executes a jQuery line that changes the css style of the element involved. 请注意,ELSE语句执行jQuery行,该行更改所涉及元素的css样式。
How do i go about doing this? 我该怎么做呢?
Anyone have any suggestions / examples of how I could implement a PHP if/else and change css styles with jQuery inside the PHP if/else statement? 任何人有任何建议/示例如何在PHP if / else语句中使用jQuery实现PHP if / else和更改css样式?
You can echo the HTML for a style element and throw the CSS inside that. 您可以回显样式元素的HTML并将CSS放入其中。
else {
echo '<style type="text/css">
#id-element {
display: none;
}
</style>';
}
Reckon you could do something like this: 估计你可以做这样的事情:
<?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; ?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.