使用数据库中的所有数据数组,如何使用enable \ disable字段创建复选框?

I want to create a table with question, checkbox and textbox. All questions are in a database and I call them in array. Then, I create a disable textbox and enable it when the checkbox is checked.

So the problem is, how can I make all the checkboxes and textboxes use the script in the array? Because it only seems to apply to the first row, why?

$(function() {
    $('#checkservice<?php $ID ?>').click(function() {
        $('#txtpercent<?php $ID ?>').prop('disabled', !this.checked);
     });
});

Above is my javascript. This works perfectly.

<?php
$query1 = mysql_query("SELECT * FROM ftrquestion ORDER BY ID") or die("could not search!");
    $count1 = mysql_num_rows($query1);

    if ($count1 = 0){
        $output = 'Theres was not search result !';
        } else {
        while ($row1 = mysql_fetch_array($query1)) {
            $ID = $row1['ID'];
            $MCPA = $row1['MCPA'];
            $quesDescBM = $row1['quesDescBM'];
            $quesDescBI = $row1['quesDescBI'];
            ?>

            <tr height="55px">
            <td ><center><?php echo $ID ?></center></td>
            <td ><?php echo $MCPA ?></td>
            <td ><span class="BM"><?php echo $quesDescBM ?>  </span> <span class="BI"><?php echo $quesDescBI ?> </span></td>
            <td ><a href=#><img src="images.png"></td>
            <td><input type="checkbox" id="checkservice<?php $ID ?>" name="checkservice>"></td> 
            <td><input type="text" id="txtpercent<?php $ID ?>" name="txtpercent"  size="1" maxlength="3" disabled> </td>
            </tr>
            <?php
            }
        }
?>
$(function() {
    $('#checkservice<?php $ID ?>').on('click', function() {
        $('#txtpercent<?php $ID ?>').prop('disabled', !this.checked);
     });
});

Maybe the elements don't exist at the time you add the click function? You can use the on() method to add functions that don't already exist in the DOM. You can read about delegated events here: http://api.jquery.com/on/

EDIT

You need to add the click function to every element, so you either create a loop in php and create one function for every ID or you add a class to your input and add the function to that class.

$(function() {
    $('.checkservice').on('click', function() {
        $(this).parent().next().children('input').prop('disabled', !this.checked);
     });
});

and

<td><input type="checkbox" id="checkservice<?php $ID ?>" class="checkservice" name="checkservice>"></td>