PHP 将类添加到 html div
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11852425/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 02:16:15 来源:igfitidea点击:
PHP add class to html div
提问by Pullapooh
i would like to add a class to my html (.complete) with php:
我想用 php 向我的 html (.complete) 添加一个类:
if( get_field('to-do-repeater') )
{
Add (complete) class to <div class="to-do to-do-wrap"> should be <div class="to-do to-do-wrap complete">
}
else
{
Do nothing
}
回答by Oussama
Try this code :
试试这个代码:
<div class="to-do to-do-wrap<?php echo get_field('to-do-repeater') ? ' complete' : '' ?>"></div>
回答by PriestVallon
<?php
echo "<div class=\"to-do to-do-wrap ";
if(get_field('to-do-repeater'))
{
echo "complete";
}
echo " \"></div>";
?>

