gpt4 book ai didi

javascript - 在 .click() 事件到 .get() 页面并替换 jquery 中的 .html()

转载 作者:行者123 更新时间:2023-12-02 19:34:12 25 4
gpt4 key购买 nike

我有 div class="contentBlock" ,它被视为更新的容器

 <div class="contentBlock"></div>

我编写的脚本不起作用:c

$(document).ready(function(){
$('.postLink').on('click', function () {
$.get("page.php", function (data) {
$(".contentBlock").html(data);
});
});
});

我有一个 anchor html

<div class="box"> 
<a class="postLink" "href="#">
<h1 title="Light me up"></h1>
<div class="innerbox">
<figure><img src="http://cpsr-rspc.hc-sc.gc.ca/PR-RP/servlet/ShowImage?photoId=1789" /></figure>
<ul class="categorySelect">
<li class="print"></li>
<li class="video"></li>
<li class="web"></li>
</ul>
</div>
</a>
</div>

page.php 只是一个 img 标签和一些 lorem。

我从未使用过 .get() 我确信我使用它不正确。另外,我应该在哪里添加加载 .gif 的过渡和加载时的淡入淡出?

最佳答案

<a class="postLink" "href="#">

应该是

<a class="postLink" href="#">

您有额外的报价。

$(document).ready(function(){
$(".postLink").on('click', function () {
// load in animation.gif here
$(".contentBlock").load("page.php", function() {
// end loading animation now
});
});
});

在 jQuery 中使用加载正是为了这个目的。

这是用于加载的 jQuery 文档:http://api.jquery.com/load/

关于javascript - 在 .click() 事件到 .get() 页面并替换 jquery 中的 .html(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11127694/

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