首页 > 解决方案 > 如何使用 php 在输入标签中使用条件?

问题描述

如果特定条件为真,则将输入字段设为只读。

$todayDate = date('Y-m-d');

这是条件

$row["date"] == $todayDate (make input readonly  true otherwise false)
while($row = $result->fetch_assoc()) {
    $output .= '
        <tbody><tr>
            <td>'.$row["date"].'</td>
            <td><input type="text" value = "'.$row["actual_closing_balance"].'"></td>
            </tr>
        </tbody>';
}

标签: phpmysql

解决方案


做这个:

$readonly = '';
if($row['date'] == $todayDate){
    $readonly = 'readonly';
}


'<input type="text" value = "'.$row["actual_closing_balance"].' '.$readonly.' />';

推荐阅读