使用以下代码 -
<div class="my"><?php
$i=0;
while ($ass = mysql_fetch_array($rs)) {$i++;?>
<input type="checkbox" name="fees_name[]" id="fee_name[<?php echo $i?>]" value="<?php echo $ass['fees_name']; ?>" onChange='if(this.checked){toggleReadonly(this,true);} else{toggleReadonly(this,false)}'>
<?php echo $ass['fees_name']; ?>
<div style="padding:0px 10px 0px 0px; float: right;">
<input id="fee_amt[<?php echo $i?>]" class="fee_amt" type="text" placeholder="amt" name="fees_amt[]" readonly>
</div> <br><br><?php
}?>
JavaScript 代码
function toggleReadonly(chk_element, status)
{
chk_element_no=chk_element.id.substring(chk_element.id.indexOf('[')+1, chk_element.id.indexOf(']'));
txt_element_id="fee_amt["+chk_element_no+"]";
if(status==true)
document.getElementById(txt_element_id).readOnly=false;
else
document.getElementById(txt_element_id).readOnly=true;
}
检查这个小提琴。
检查以下类似的示例代码并执行它-
1.php
<html>
<head>
<script>
function toggleReadonly(chk_element, status)
{
chk_element_no=chk_element.id.substring(chk_element.id.indexOf('[')+1, chk_element.id.indexOf(']'));
txt_element_id="fee_amt["+chk_element_no+"]";
if(status==true)
document.getElementById(txt_element_id).readOnly=false;
else
document.getElementById(txt_element_id).readOnly=true;
}
</script>
</head>
<body>
<div class="my"><?php
$i=0;
while ($i++<=10) {?>
<input type="checkbox" name="fees_name[]" id="fee_name[<?php echo $i;?>]" value="<?php echo $i; ?>" onChange='if(this.checked){toggleReadonly(this,true);} else{toggleReadonly(this,false)}'>
<?php echo $i; ?>
<div style="padding:0px 10px 0px 0px; float: right;">
<input id="fee_amt[<?php echo $i;?>]" class="fee_amt" type="text" placeholder="amt" name="fees_amt[]" readonly>
</div> <br><br><?php
}?>
</div>
</body>
</html>