Ich versuche Javascript zu verwenden, um Eingabefelder nur schreibgeschützt zu setzen, wenn sie keinen Wert enthalten, d. H. Wenn sie null sind. dies ist mein Code, ich bin keine Fehler vom Debugger empfangen, aber es weigert sich einfach zu arbeiten, könnte jemandVerwenden von Javascript zum Festlegen der Eingabe für schreibgeschützt
//checkScore();
function checkScore(){
document.getElementById('score_row1').readonly = true;
var scores = document.getElementsByClassName("score_holder");
var i;
for(i=0; i<scores.length; i++){
if(scores[i].value!=null){
scores[i].readonly="readonly";
}
}
}
<!doctype html>
<html>
<head>
</head>
<body onload="checkScore()">
<table align="center" cellpadding="3">
<tr valign="baseline">
<td colspan="3" align="center" id="course_row25" value="EDU-101"><strong>EDUCATION COURSES</strong></td>
</tr>
<tr>
<td align="right">
<input name="course_row1" type="text" id="course_row1" title="EDU-101: Historical Foundation of Education" value="EDU-101" size="5" readonly="readonly" />
</td>
<td> </td>
<td>
<input type="text" value="30" size="5" class="score_holder" />
</td>
</tr>
<tr>
<td align="right" id="course_row1" name="course_row1" value="EDU-101">
<input name="course_row1" type="text" id="course_row1" title="EDU-101: Historical Foundation of Education" value="EDU-101" size="5" readonly="readonly" />
</td>
<td> </td>
<td>
<input type="text" size="5" class="score_holder" />
</td>
</tr>
<tr>
<td align="right" id="course_row1" name="course_row1" value="EDU-101">
<input name="course_row1" type="text" id="course_row1" title="EDU-101: Historical Foundation of Education" value="EDU-101" size="5" readonly="readonly" />
</td>
<td> </td>
<td>
<input type="text" value="10" size="5" class="score_holder" />
</td>
</tr>
</table>
</body>
</html>
sein sollte 'readOnly' – epascarello
' Partituren [i] .readonly = "Read-only ";" - Die schreibgeschützte DOM-Eigenschaft ist ein boolescher Wert. Es kann die Werte "wahr" und "falsch" haben. '" readonly "' funktioniert nur, weil die Zeichenfolge in einen booleschen Wert umgewandelt wird. – Quentin
als @Quentin erwähnt, in Bezug auf [hier] (https://www.w3schools.com/jsref/prop_text_readonly.asp) ist es Punkte [i] .readOnly = wahr; –