我有一些代码用于在未检查无线电但仅使用内部编码时禁用文本字段。每当我尝试将它放在外部页面上时它都无法工作。
有人能指出我犯错的地方吗?
<script>
window.onload = function() {
document.getElementById('Ingredient').onchange = disablefield;
document.getElementById('Misc').onchange = disablefield;
document.getElementById('Size').disabled = false;
document.getElementById('Color').disabled = false;
document.getElementById('Brandname').disabled = false;
document.getElementById('Misc').checked = false;
document.getElementById('Ingredient').checked = false;
}
function disablefield()
{
if (document.getElementById('Ingredient').checked == true ){
document.getElementById('Brandname').value = '';
document.getElementById('Size').value = '';
document.getElementById('Color').value = '';
document.getElementById('Size').disabled = true;
document.getElementById('Color').disabled = true;
document.getElementById('Brandname').disabled = false;}
else if (document.getElementById('Misc').checked == true ){
document.getElementById('Brandname').value = '';
document.getElementById('Size').value = '';
document.getElementById('Color').value = '';
document.getElementById('Size').disabled = false;
document.getElementById('Color').disabled = false;
document.getElementById('Brandname').disabled = true;}
}
</script>
我确实把这段代码放在html
的头部<script type="text/javascript" src="Additem.js"></script>
单选按钮代码
<input name="ItemType" type="radio" value="Ingredient" id="Ingredient" onclick="disablefield()"/>
Ingredient
<input name="ItemType" type="radio" value="Misc" id="Misc" onclick="disablefield()"/>
Misc. Item
文本域代码
<input type="text" name="Brandname" id="Brandname"/>
<input type="text" name="Size" id="Size"/>
<input type="text" name="Color" id="Color"/>
答案 0 :(得分:0)
尝试将其放在文档底部,</body
标记之前:
<script type="text/javascript" src="Additem.js"></script>