如何使按钮ID一个变量在php中使用


How to make the button ID a variable to use in php?

我试图将ID设置为变量,如何才能?

<?php
    $counter = 1;
    $i = 1;
    $testvar[$i] = ("NUMBER" + $i);
?>
<input type="button" id="<?php echo($testvar[$i]); ?>"/>
<script>
    var btn['<?php echo($i); ?>'] = document.getElementById("<?php echo($testvar[$i]); ?>");
    btn.onclick = CreateButton;
    function CreateButton(){
    <?php
        $counter++;
        while ($i < $counter){
            i++;
            echo("<input type='button' id='<?php echo($testvar[$i]); ?>'/>");
        }        
    ?>
};
</script>

ID未被识别为变量

您忘记将$添加到我们的一个变量:

<?php
    $counter++;
    while ($i < $counter){
        $i++; //Missing $
        echo("<input type='button' id='<?php echo($testvar[$i]); ?>'/>");
    }        
?>

作为旁注,你的问题真的不清楚。