[英]hiding a div with a value/ output from a php and css stament
I am going to use a button to set a value to a variable, I want to be able to hide a <div>
using the result from a PHP / CSS statement. 我将使用按钮将值设置为变量,我希望能够使用来自PHP / CSS语句的结果来隐藏
<div>
。
$day
and $time
would be set using the CSS set_date()
function. $day
和$time
将使用CSS set_date()
函数设置。 Example below: 下面的例子:
//Check if $day is within a business week/day
if ($day > 5) {
//Hide the div
//Check $time is within business hours and day
} else if ($time>=9 && $time<17) {
//Show the div
//Otherwise
} else {
//Make div invisible
}
That's how I want to do it but it isn't working as expected, any help would be much appreciated! 这就是我想要的方法,但是它没有按预期工作,非常感谢您的帮助!
If necessary, here's the button resource: 如有必要,这是按钮资源:
if ($day > 5) {
$div='';
}
//check if it is within business hours and day
//if yes show div
elseif ($time>=9 && $time<17) {
$div='<div> whatever inside</div>';
}
//if not make div not visable
else {
$div='';
}
//if you use $div="<div>i am a div with a " inside </div>";
//then do this $div="<div>i am a div with a \" inside</div>"; the \allows the php to know it must not use the next character as code
in your html 在你的HTML
<?php echo $div;?>
<?php
//check if it is within a business week/day
if ($day > 5) {
?>
//hide the div
<script language="javascript">
$(document).ready(function() {
$("#mydiv").hide();
});
</script>
<?php
}
//check if it is within business hours and day
//if yes show div
elseif ($time>=9 && $time<17) {
?>
//hide the div
<script language="javascript">
$(document).ready(function() {
$("#mydiv").show();
});
</script>
<?php
}
//if not make div not visable
else {
<script language="javascript">
$(document).ready(function() {
$("#mydiv").hide();
});
</script>
}
?>
Did you checked the PHP alternative syntax 您是否检查过PHP替代语法
you can simply do that 你可以简单地做到这一点
<?php if($day > 5): ?>
<div id="button1" style="display:none"> Hidden </div> <!-- This is plain html -->
<?php elseif($time >= 9 && $time < 17): ?>
<div id="button2"> Button text </div>
<?php else: ?>
<div id="button3" style="opacity:0"> Invisible </div>
<?php endif; ?>
It is really great and clean to use PHP alternative syntax if you mixing HTML and PHP, you're completely clean and clear when using Quotes. 如果将HTML和PHP混合使用,使用PHP替代语法确实很棒,而且干净,使用Quotes时,您完全干净。
Does the <div>
need to be invisible? <div>
是否需要不可见? Couldn't you just not have an else condition? 您不能没有其他条件吗?
With just one conditional you can write 只需一个条件,您就可以编写
if (($time>=9 && $time<17) && ($day < 5)) {
// Div is shown 9am - 7pm on weekdays
// echo div
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.