【问题标题】:change value of input button inside php file [closed]更改php文件中输入按钮的值[关闭]
【发布时间】:2021-03-15 16:46:42
【问题描述】:

我正在尝试编写一个跟踪不同用户的代码,并从 MySQL 表中插入值

<td align="center">
<input type="button" name="<?php echo $id; ?>" id="<?php echo $id; ?>" value="suivre"> 
</td>

我想知道每次点击按钮后有没有解决办法,值变成了下面

【问题讨论】:

  • 这能回答你的问题吗? Changing button text onclick
  • 但是我的id变了,怎么把$id放到document.getElementById()中
  • 您不必使用getElementById。例如,请参阅this comment
  • 不行,能不能给我写个代码让我测试一下

标签: javascript php html mysql


【解决方案1】:

您未成功,因为 id 属性不能以数字开头。 根据您在此处收到的 javascript 示例尝试以下基本示例

带有 getElementById 的示例 1

<input onclick="change()" type="button" name="<?php echo $id; ?>" id="el_<?php echo $id; ?>" value="suivre"> 
<script>
function change(){
  document.getElementById("el_<?php echo $id; ?>").value="Hello world1";
}
</script>

Example2 没有 id 或 getElementById

<input onclick="change(this)" type="button" name="<?php echo $id; ?>" value="suivre"> 
<script>
function change(el){
  el.value="Hello world2";
}
</script>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-09-20
    • 2014-08-23
    • 1970-01-01
    • 1970-01-01
    • 2020-09-03
    • 2019-06-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多