我有一个表单,是用来处理节假日的一些特殊要求的,做成了table的形式,由于节假日的个数是变化的,所以这个table的行数是不固定的。我的php来创建的table如下:
<table border='1' style='margin-left:250px;'>
<tr><td style="width:150px;"> HOLIDAY NAME</td> <td style="width:150px;">HOLIDAY DATE</td> <td style="width:150px;">STATUS</td> <td style="width:150px;">SURCHARGE</td> <td style="width:250px;">SURCHARGE PLU</td></tr>
<?php for( $i=0;$i<$num_holidays;$i++ ){
echo "<tr><td >";
echo $holiday_array[$i]['public_name'];
echo "</td><td >";
echo $holiday_array[$i]['public_date'];
echo "</td><td >";
?>

<select name='<?php echo $i+1;?>_stat'  id='<?php echo $i+1;?>_stat' style='width:70px;'> 
<option value='0'> Normal </option>
<option value='1'> Closed </option>
<option value='2'> Surcharge </option>";
</td><td>

<select name='<?php echo $i+1;?>_surcharge' id='<?php echo $i+1;?>_surcharge' style='width:70px;'>
<option value='0' > NO Fee </options>
<?php 
for($j=0;$j<$num_rows;$j++){ 
$value=$rate_array[$j];
?><option value=" <?php echo $j+1; ?> " >
<?php echo $value ?></option><?php } ?>  
</select>
%</td>
<td> <input type="text" name='<?php echo $i+1;?>_plu'  id='<?php echo $i+1;?>_plu' style='width:150px;' >   </td></tr>
<?php } ?>
</table>
做出来的结果应该是有这些项 0_stat,0_surcharge,0_plu,1_stat,1_surcharge,1_plu,2_stat,2_surcharge,2_plu,等等 有这么一个要求我不会做,0_stat, 1_stat等都是一个select, 要求当这个select的值为“surcharge”时, 对应的X_surcharge 和X_plu是激活的,要不得话,就是disable的,请问这个该如何实现?

解决方案 »

  1.   


    window.onload = function(){
    var sels = document.getElementsByTagName("select");
    for (var i=0;i<sels.length ; i++)
    {
    if (/(\d)+_stat/.test(sels[i].id))
    {
    sels[i].onchange = function(i){
    return function(){
    document.getElementById(i+"_surcharge").
    disabled = this.options[this.selectedIndex].text!="surcharge";
    document.getElementById(i+"_plu").disabled=this.options[this.selectedIndex].text!="surcharge"; }
    }(RegExp.$1);
    sels[i].onchange();
    }
    }
    }