这是我的HTML跨度和输入行,我将其设置为显示:none(硬编码)。
如果accountstatus等于animaldead ,我想显示这一点
这是我的HTML输入和跨度
<span class = 'v10' style="display:none;"><span style='color:#FF0000;'>*</span>Inception Date:<br /></span>
<input name='period_from' class = 'v11' value = "<?php echo $incepd; ?>" onblur="validateg('<?php echo $fieldstovalidate; ?>','<?php echo $submitbtns; ?>');" id = 'period_from' onfocus=showCalendar('',this,this,'".$period_from."','period_fromd',0,23,1); onfocus=returbcolorback('period_from'); style = 'height:21px;width:140px;display:none' type='text' />
这是我的if语句
if(strtolower($accountstatus) == 'animaldead')
{ $trutype = "selected";
how will I show it here......
}
$style = 'none';
if(strtolower($accountstatus) == 'animaldead'){
$trutype = "selected";
$style = 'block';
}
变化幅度就像
<span class = 'v10' style="display:<?php echo $style; ?>;">
使用这种方式,您不需要复制相同的代码两次。
$block = "block";
$none = "none";
if(strtolower($accountstatus) == 'animaldead')
{ $trutype = "selected";
?> <span class = 'v10' style="display:<?php echo $block; ?>; "><span style='color:#FF0000;'>*</span>Inception Date:<br /></span>
<input name='period_from' class = 'v11' value = "<?php echo $incepd; ?>" onblur="validateg('<?php echo $fieldstovalidate; ?>','<?php echo $submitbtns; ?>');" id = 'period_from' onfocus=showCalendar('',this,this,'".$period_from."','period_fromd',0,23,1); onfocus=returbcolorback('period_from'); style = 'height:21px;width:140px;display:none' type='text' />
}
else{
<span class = 'v10' style="display:<?php echo $none; ?>; "><span style='color:#FF0000;'>*</span>Inception Date:<br /></span>
<input name='period_from' class = 'v11' value = "<?php echo $incepd; ?>" onblur="validateg('<?php echo $fieldstovalidate; ?>','<?php echo $submitbtns; ?>');" id = 'period_from' onfocus=showCalendar('',this,this,'".$period_from."','period_fromd',0,23,1); onfocus=returbcolorback('period_from'); style = 'height:21px;width:140px;display:none' type='text' />
}
创建两个变量,一个用于显示块,另一个用于不显示。现在php和html可以一起编写,所以如果它是==animaldead,那么您可以放置display:block,如上面的代码所示。否则你不显示。。。干杯:D
比在html标记内硬编码属性更优雅的方法是使用一个特殊的css类,例如hidden:
.hidden {
display: none;
}
当您呈现HTML代码时,您可以选择将此类添加到标签中或不添加到标签:
<span class = 'v10 <?php if (strtolower($accountstatus) == 'animaldead') echo '.hidden'; ?>'><span style='color:#FF0000;'>*</span>Inception Date:<br /></span>