gpt4 book ai didi

javascript - 尝试使用jQuery使模态数据动态化

转载 作者:行者123 更新时间:2023-12-01 16:25:04 25 4
gpt4 key购买 nike

我正在为一个电子商务项目做快速浏览。到目前为止,我已经完成了以下工作:

function quickView(){
$('.btn-quick-view').on('click', function(){
let id = $(this).attr('value');
let url = '{{ route("quick", ":data") }}';
url = url.replace(":data", id);
$.ajax({
method: "GET",
url: url,
dataType: 'json',
success(response){
let html = "<div class='modal-dialog modal-dialog-centered' role='document'><div class='modal-content'><span class='modal-close' data-dismiss='modal'><i class='icon-cross2'></i></span><article class='ps-product--detail ps-product--fullwidth ps-product--quickview'><div class='ps-product__header'><div class='ps-product__thumbnail' data-vertical='false'><div class='ps-product__images' data-arrow='true'>";
$.each(response.images, function(key, value){
html += "<div class='item'><img src='"+value.image+"'></div>";
});
html += "</div></div><div class='ps-product__info'><h1>"+response.name+"</h1><div class='ps-product__meta'><p>Brand:<a href='shop-default.html'>Sony</a></p><div class='ps-product__rating'><select class='ps-rating' data-read-only='true'><option value='1'>1</option><option value='1'>2</option><option value='1'>3</option><option value='1'>4</option><option value='2'>5</option></select><span>(1 review)</span></div></div><h4 class='ps-product__price'>$36.78 – $56.99</h4><div class='ps-product__desc'><p>Sold By:<a href='shop-default.html'><strong> Go Pro</strong></a></p>description</div><div class='ps-product__shopping'><a class='ps-btn ps-btn--black' href='#'>Add to cart</a><a class='ps-btn' href='#'>Buy Now</a><div class='ps-product__actions'><a href='#'><i class='icon-heart'></i></a><a href='#'><i class='icon-chart-bars'></i></a></div></div></div></div></article></div></div>";
$('#product-quickview').html(html);
$.getScript('/frontend/js/jquery-1.12.4.min.js');
},
error: function(response){
toastr.error('Something went wrong!');
}
});
})
}
quickView();
由于此模型使用光滑的来显示产品图像,因此我希望jquery能正常工作。我试图用 $.getScript('/frontend/js/jquery-1.12.4.min.js');加载jquery,但是没有用。为了使该模型动态工作,我该怎么办?

最佳答案

function quickView(){
$('.btn-quick-view').on('click', function(){
let id = $(this).attr('value');
let url = '{{ route("quick", ":data") }}';
url = url.replace(":data", id);
$.ajax({
method: "GET",
url: url,
dataType: 'json',
success(response){
let html = "<div class='modal-dialog modal-dialog-centered' role='document'>
<div class='modal-content'><span class='modal-close' data-dismiss='modal'><i class='icon-cross2'></i></span>
<article class='ps-product--detail ps-product--fullwidth ps-product--quickview'>
<div class='ps-product__header'>
<div class='ps-product__thumbnail' data-vertical='false'>
<div class='ps-product__images' data-arrow='true'>";
$.each(response.images, function(key, value){
html += "<div class='item'><img src='"+value.image+"'></div>";
});
html += "</div>
</div>
<div class='ps-product__info'>
<h1>"+response.name+"</h1>
<div class='ps-product__meta'>
<p>Brand:<a href='shop-default.html'>Sony</a></p>
<div class='ps-product__rating'><select class='ps-rating' data-read-only='true'>
<option value='1'>1</option>
<option value='1'>2</option>
<option value='1'>3</option>
<option value='1'>4</option>
<option value='2'>5</option>
</select><span>(1 review)</span></div>
</div>
<h4 class='ps-product__price'>$36.78 – $56.99</h4>
<div class='ps-product__desc'>
<p>Sold By:<a href='shop-default.html'><strong> Go Pro</strong></a></p>description
</div>
<div class='ps-product__shopping'><a class='ps-btn ps-btn--black' href='#'>Add to cart</a><a class='ps-btn' href='#'>Buy Now</a>
<div class='ps-product__actions'><a href='#'><i class='icon-heart'></i></a><a href='#'><i class='icon-chart-bars'></i></a></div>
</div>
</div>
</div>
</article>
</div>
</div>";
$('#product-quickview').html(html);
//initialize your slick lib
$('.product-images').slick();
$.getScript('/frontend/js/jquery-1.12.4.min.js');
},
error: function(response){
toastr.error('Something went wrong!');
}
});
})
}
quickView();

关于javascript - 尝试使用jQuery使模态数据动态化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63086018/

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