简体   繁体   English

如何使按钮ID成为php中使用的变量?

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

I am trying to set the ID as a variable, how can i? 我正在尝试将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>

The ID is not being reconigzed as a variable 该ID未重新配置为变量

You forgot to add the $ to one of our variables: 您忘记将$添加到我们的变量之一中:

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

And as a sidenote, your question is really unclear. 另外,您的问题确实不清楚。 You should describe better what is not working. 您应该更好地描述什么不起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM