gpt4 book ai didi

javascript - 页面在模态弹出窗口上滚动到顶部

转载 作者:行者123 更新时间:2023-11-29 17:50:19 24 4
gpt4 key购买 nike

我正在使用 bootstrap(前端)和 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>

Ajax

$(".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">&times;</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;
}

这是我的演示网站链接

http://cableandmedia.com/ayurstore/

最佳答案

我觉得罪魁祸首是href="#"

你可以做两件事,

  1. 只需删除href="#"
  2. 更改 <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"如果您采用第二种方法。

关于javascript - 页面在模态弹出窗口上滚动到顶部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44472611/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com