简体   繁体   中英

How to write class attribute for html element in php file?

Cannot write class attribute in php file for html element. Here is my code

echo '<div><p class="'.($value->getIsRequire() == 1) ? 'required' : ''.'">
</p> <input type="text" name="field" id="option-value" /></div>';

My output should be if the condition is true the class should be required otherwise the class should be empty but i got output as required text instead of input box.

Result I got is

在此处输入图片说明

try this, you should wrap it in parentheses :

echo '<div><p class="'.(($value->getIsRequire() == 1) ? 'required' : '').'">
</p> <input type="text" name="field" id="option-value" /></div>';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM