如何通过单击获得不同的值。如果我单击第一个立即购买按钮,则想获得“ Pendrive,300 gms,600”,请找到以下代码。当我点击“立即购买第二个按钮”时,我想获得“移动设备,200gms,650”。在另一页中。
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>
<div class="col-sm-12 col-xs-12">
<div class="tab-pane active" id="all">
<div class="row">
<div class="col-md-4 col-sm-6 col-xs-12">
<diV class="box">
<div class="image">
</div>
<div class="caption">
<h4>Pendrive</h4>
<p class="des">300 grams</p>
<div class="price"> ₹ 600</div>
<button type="button" class="btn btn-warning">Buy Now</button>
</div>
</div>
</div>
<div class="col-md-4 col-sm-6 col-xs-12">
<diV class="box">
<div class="image">
</div>
<div class="caption">
<h4>Mobile</h4>
<p class="des">200 gms</p>
<div class="price"> ₹ 650</div>
<button type="button" class="btn btn-warning">Buy Now</button>
</div>
</div>
</div>
</div>
答案 0 :(得分:0)
您可以使用ajax在其他PHP页面中传递选定的值,并在其中应用逻辑。
尝试一下:-
<div class="col-sm-12 col-xs-12">
<div class="tab-pane active" id="all">
<div class="row">
<div class="col-md-4 col-sm-6 col-xs-12">
<diV class="box">
<div class="image">
</div>
<div class="caption">
<h4>Pendrive
</h4>
<p class="des">300 grams
</p>
<div class="price"> ₹ 600
</div>
<button type="button" class="btn btn-warning" onclick="sendSelectedValue('Pendrive, 300 grams, 600');">Buy Now
</button>
</div>
</div>
</div>
<div class="col-md-4 col-sm-6 col-xs-12">
<diV class="box">
<div class="image">
</div>
<div class="caption">
<h4>Mobile
</h4>
<p class="des">200 gms
</p>
<div class="price"> ₹ 650
</div>
<button type="button" class="btn btn-warning" onclick="sendSelectedValue('Mobile,200 gms,650 ');">Buy Now
</button>
</div>
</div>
</div>
</div>
<script type="text/javascript">
function sendSelectedValue(val){
$.ajax({
type: "POST",
url: 'ajax_stack.php',
data: {
selected: val}
,
success: function(val){
alert(data);
}
});
}
</script>