PHP代码无法在HTML输入标记中正确解析

时间:2017-02-28 15:24:17

标签: php html mysql input

我有从数据库中读取的scrpit。它在其他文本框中正确显示,除了一个应该显示学生测试值1的文本框。 逻辑是>如果值> 0,则必须禁用该文本框。

以下是无法在文本框中正确显示的代码。我错过了什么?

<td>Test 1</td>
<td><input class="form-control" disabled placeholder="Enter Test 1" id="test1" name="test_1" type="text" value="
<?php 
echo $test1;
if($test1>0){
?>
<script>
document.getElementById("test1").disabled = true;
</script>
<?php
}
?>"/>
</td>

1 个答案:

答案 0 :(得分:4)

简单的解决方案是:

<td>
    <input 
        class="form-control" 
        placeholder="Enter Test 1" 
        id="test1" 
        name="test_1" 
        type="text" 
        value="<?php echo $test1;?>" 
        <?php if ($test1 > 0) echo ' disabled';?>
    >
</td>