gpt4 book ai didi

javascript - Jquery load() 和 colorbox() 在一起

转载 作者:行者123 更新时间:2023-11-30 09:01:24 25 4
gpt4 key购买 nike

我正在尝试使用 jQuery 加载函数加载页面的一部分并使用 colorbox 显示它。我目前正在使用

       $(document).ready(function()
{
$(".rest-menuitem a").click(function(event)
{
event.preventDefault();
var elementURL = $(this).attr("href");
$.colorbox({ html: $.load(elementURL+ " .product" ) , width:'1000px',height:'80%', href: finalURL);
});
});

这是行不通的,因为我们需要一个加载函数的选择器。有没有办法使用负载来解决我的问题?如果没有,是否有替代解决方案?

最佳答案

我想你在看的是.get()方法。它从指定的 url 加载数据并在数据可用时执行回调。然后您可以自己过滤收到的 html 并使用您的 colorbox 插件。

像这样:

$(document).ready(function() {
$(".rest-menuitem a").click(function(event) {
event.preventDefault();
$.get($(this).attr("href"), function(data) {
$.colorbox({
html: $(data).find('.product'),
width: '1000px',
height: '80%',
href: finalURL);
});
});;
});
});

关于javascript - Jquery load() 和 colorbox() 在一起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8947930/

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