Javascript 由多个按钮激活的jqueryajax
我从mysql中提取数据并制作4个按钮;然后尝试使用jquery/ajax调用事件。只有第一个有效,其他3个无效 以下是查询:Javascript 由多个按钮激活的jqueryajax,javascript,jquery,mysql,ajax,Javascript,Jquery,Mysql,Ajax,我从mysql中提取数据并制作4个按钮;然后尝试使用jquery/ajax调用事件。只有第一个有效,其他3个无效 以下是查询: <div class="row"> <? $query="SELECT * from product_bid order by RAND() LIMIT 4"; $result=mysql_query($query); while($row=mysql_fetc
<div class="row">
<? $query="SELECT * from product_bid order by RAND() LIMIT 4";
$result=mysql_query($query);
while($row=mysql_fetch_array($result))
{ ?>
<div class="col-sm-3">
<div class="product">
<div class="title"><strong>Iphone 16GB</strong></span></div>
<img class="img-responsive" src="">
<small>ราคา <?=$row['price']; ?> บาท</small><hr>
<span class="countdown">00:23:32</span> <br>
<span class="price" id="price"><?= $row['total_bids']; ?> บาท</span> <br>
<span class="user">user</span> <br>
<input type="hidden" id="productid" name="id" value="<?= $productid=$row['id']; ?>">
<span class="bid btn btn-button btn-success btn-md" value="Bid">Bid</span>
</div>
</div>
<? }
?>
</div>
Iphone 16GB
ราคา บาท
00:23:32
บาท
用户
页面上不能有多个id相同的元素。请将productid更改为类,或者以另一种方式更改它,使每个元素的id都是唯一的。价格也一样。如果你那样做的话
$(".bid").click(function () {
buttonClick($(this));
});
function buttonClick($bid) {
var $parent = $bid.parent();
var productid = $parent.find('.productid').val();
var $price = $parent.find('.price');
$.ajax({
type: "GET",
url: "bid.php",
data: 'id='+ productid,
// success: function(msg){
// $price.html(msg);
// }
}); // Ajax Call
}
$(".bid").click(function () {
buttonClick($(this));
});
function buttonClick($bid) {
var $parent = $bid.parent();
var productid = $parent.find('.productid').val();
var $price = $parent.find('.price');
$.ajax({
type: "GET",
url: "bid.php",
data: 'id='+ productid,
// success: function(msg){
// $price.html(msg);
// }
}); // Ajax Call
}