我有一份商店物品清单。每个项目都以一种形式显示其价值。<?php if($statement->execute()){ $result = $statement->fetchAll(); $output = ''; foreach($result as $row) { $output .= ' <div class="col-md-3" style="margin-top:12px;"> <div class="item-content" align="center"> <div class="img-container"> <img src="../administrar/application/admin/productos/'.$row["image"].'" class="img-responsive" /><br /> <h4 class="text-info">'.$row["name"].'</h4> <h4 class="text-danger">$ '.$row["price"] .'</h4> <input type="text" name="quantity" id="quantity' . $row["id"] .'" class="form-control" value="1" style="text-align:right;"/> <input type="hidden" name="hidden_name" id="name'.$row["id"].'" value="'.$row["name"].'" /> <input type="hidden" name="hidden_price" id="price'.$row["id"].'" value="'.$row["price"].'" /> <div class="input-group"> <span class="input-group-btn"> <button type="button" class="btn btn-danger btn-number" name="restar" id="'.$row["id"].'" " > <span class="glyphicon glyphicon-minus"></span> </button> </span> <span class="input-group-btn"> <button type="button" class="btn btn-success btn-number" name="sumar" id="sumar""> <span class="glyphicon glyphicon-plus"></span> </button> </span> </div> 我需要确定用户何时单击某个表单项中的“重新启动”按钮。这是我当前的脚本,但它没有启动预期的警报。<script type="text/javascript"> $(document).ready(function(){ var product_id = $(this).attr("id"); $('#restar'+'product_id+').on('click', function(event) { alert("ssssspp2"); }); });</script>
1 回答
拉莫斯之舞
TA贡献1820条经验 获得超10个赞
用于class描述相似的对象,例如:
$('.js-some-btn').click(function() {
console.log("I'm button");
console.log("My id is " + $(this).attr('id'));
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button type="button" class="btn btn-success btn-number js-some-btn" name="sumar1" id="id1">btn 1</button>
<button type="button" class="btn btn-success btn-number js-some-btn" name="sumar2" id="id2">btn 2</button>
这种方法允许您为具有提供的类的所有按钮编写一次单击处理程序。
- 1 回答
- 0 关注
- 96 浏览
添加回答
举报
0/150
提交
取消