使用 jquery 创建唯一 id 以在 bxslider 中使用
我想这很简单,但我对 jquery 没有任何经验。我在我的 WordPress 主题中发布的每篇文章中都使用 bxslider,并且需要 jquery 指向许多唯一的 id,不仅指向 work1,还指向 work2、work3 等。
The markup is this:
<ul id="work1">
<li></li>
<li></li>
</ul>
<ul id="work2">
<li></li>
<li></li>
</ul>
...
和代码:
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery('#work1').after('<div class="work-pager"></div>');
jQuery('#work1').bxSlider({
mode: 'horizontal',
infiniteLoop: false,
speed: 500,
pause: 8000,
auto: false,
pager: true,
controls: false,
pagerSelector: '.work-pager'
});
});
</script>
I guess this is pretty simple but I have no experience with jquery whatsoever. I'm using bxslider in every post I post in my wordpress theme and need the jquery to point to numerous unique id's, not only to work1, but work2, work3 and so on.
The markup is this:
<ul id="work1">
<li></li>
<li></li>
</ul>
<ul id="work2">
<li></li>
<li></li>
</ul>
...
And the code:
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery('#work1').after('<div class="work-pager"></div>');
jQuery('#work1').bxSlider({
mode: 'horizontal',
infiniteLoop: false,
speed: 500,
pause: 8000,
auto: false,
pager: true,
controls: false,
pagerSelector: '.work-pager'
});
});
</script>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这应该可以解决问题。 JSFIDDLE
This should do the trick. JSFIDDLE