javascript - 如何从所有 php 文本 id 中获取元素?
问题描述
php+js。我想getElementById所有文本id,但结果只有我能得到最后一个id。我不知道该怎么处理它...
html:
<div class="col-md-3 py-5">
<button type="button" class="btn bg-light border rounded-circle" onclick="minus()"><i class="fas fa fa-minus" ></i></button>
<input type="text" id="<?php echo $pro_id?>" value="<?php echo $pro_quantity?>" class="form-control w-25 d-inline">
<button type="button" class="btn bg-light border rounded-circle" onclick="plus()"> <i class="fas fa fa-plus" ></i></button>
</div>
js:
<script>
let count = 1;
let countEl = document.getElementById("<?php echo $pro_id;?>");
function plus(){
count++;
countEl.value = count;
}
function minus(){
if (count > 1) count--;
countEl.value = count;s
}
</script>
铬 js 照片:
解决方案
我们只能为一页使用一个 id。
使用类而不是 id。
或者如果可能的话,在 plus(id) 函数和 minus(id) 函数中传递您当前的 id
推荐阅读
- r - R - 按条件创建数据框
- angular - 文件不存在,但角度说它已经存在
- python - Python 和 Flask:IndentationError: unindent 不匹配任何外部缩进级别
- r - 使用 dplyr 计算子集内子集的比率
- c# - Gremlin cosmos:如何在重复命令中将边缘的属性值复制为顶点属性
- java - 在移动设备中显示背景良好,但在 bluestacks 中显示白色背景
- sql - 通过连接或其他方式根据匹配的 ID 在表列中填充空行
- mysql - 如何使用 MySQL 中大型数据集的 COUNT() 重新定义慢速 SQL 查询
- flutter - 收听 Firestore 集合怎么可能允许访问我不应该访问的数据?
- python - Python Dataframe:如何将列值与相邻列值映射?