我想用html5数据属性更改图像源.我已经尝试了很多方法,但到目前为止仍然无法解决,因为这里的演示是代码;
HTML标记:
<img src="http://placehold.it/300x250&text=Default%20Image" data-imgSmall="http://placehold.it/300x250&text=Small%20Image" data-imgMedium="http://placehold.it/300x250&text=Medium%20Image" data-imgLarge="http://placehold.it/300x250&text=Large%20Image" />
<button class="small">Small Image</button>
<button class="medium">Medium Image</button>
<button class="large">Large Image</button>
Run Code Online (Sandbox Code Playgroud)
jQuery代码:
var ImgSmall = $('img').data('imgSmall'),
ImgMedium = $('img').data('imgMedium'),
ImgLarge = $('img').data('imgLarge'),
img = $('img');
$('button').click(function () {
if ($(this).hasClass("small")) {
img.attr('src', ImgSmall);
alert(ImgSmall);
}
if ($(this).hasClass("medium")) {
img.attr('src', ImgMedium);
alert(ImgMedium);
}
if ($(this).hasClass("large")) {
img.attr('src', ImgLarge);
alert(ImgLarge);
}
});
Run Code Online (Sandbox Code Playgroud)
但是这段代码仍然不能正常工作,plz建议我错了,先谢谢:)
我已经使用 _S 入门主题从头开发了自定义主题。我在通过点击阅读更多按钮的 ajax 请求获取 Wordpress 下一篇文章时遇到问题。我已经尝试了很多文章,特别是以下文章,但没有运气。
参考链接:
我试过使用上面的自定义循环并使用 jquery 脚本添加自定义函数,但它以某种方式不起作用。
下面是循环代码示例:
在 index.php 中循环
<?php query_posts('showposts=5'); if (have_posts()) : while (have_posts()) : the_post(); ?>
<article class="post-item">
<h2><?php the_title(); ?></h2>
<?php the_excerpt(); ?>
</article>
<?php endwhile; ?>
<?php else : ?>
<h2>Sorry no posts are created yet.</h2>
<p>Please create some posts to see it in action.</p>
<?php endif; wp_reset_query(); ?>
<button class="load-more-btn">Load More</button>
Run Code Online (Sandbox Code Playgroud)
我在这个问题上搞砸了超过 4-5 …