[英]page scrolls to top on modal popup
我正在使用bootstrap(front end)和codeigniter開發購物車。 當添加到購物車項目時,模態彈出窗口顯示添加項目的詳細信息。 但是我的問題是頁面滾動在模式彈出窗口上移至頂部。
<a href="#" id="edit_product" data-id="<?php echo $lat['product_id'];?>" name="id" data-text="Add To Cart" class="my-cart-b item_add add_to_cart">Add To Cart</a>
阿賈克斯
$(".product_add").click(function(event) {
var currentId = globalId;
$.ajax({
type: 'POST',
url: '<?php echo site_url("ajax_controller1/product_add/'+currentId+'")?>',
data: { id:'1' },
success:function(response){
$("#cart_container1").html(response);
$("#myModal3").modal('show');
}
});/* Aajx */
});
語氣
<div class="modal fade" id="myModal3" tabindex="-1" role="dialog" style="overflow: visible;">
<div class="modal-dialog" role="document" style="overflow: visible;">
<div class="modal-content modal-info" style="overflow: visible;">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
</div>
<div class="modal-body" id="cart_container1">
</div>
</div>
</div>
</div>
我已經做了以下工作來克服這個問題
$('a.add_to_cart').click(function(e) {
e.preventDefault();
});
body.modal-open {
overflow: visible;
}
這是我的演示網站鏈接
我認為罪魁禍首是href="#"
你可以做兩件事,
href="#"
將<a>
更改為`
<button type="button" id="edit_product" data-id="<?php echo $lat['product_id'];?>" name="id" data-text="Add To Cart" class="my-cart-b item_add add_to_cart">Add To Cart</button>
這應該對您有幫助。
請注意,如果您采用第二種方法,則我添加了type="button"
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.