我有从数据库中读取的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>
答案 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>