查询字符串以控制BXSlider startSlide [英] Query String to Control BXSlider startSlide
本文介绍了查询字符串以控制BXSlider startSlide的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试让bxslider上的开始幻灯片由查询字符串控制.例如,URL http://page.html?id = 3 将开始第三张幻灯片,用户然后可以无限循环地推动幻灯片.我目前拥有的代码是:
I am trying to have the start slide on bxslider controlled by a query string. For example, the url http://page.html?id=3 would start slide three and the user could then advance the slides in an infinite loop. The code I currently have is:
$(document).ready(function(){
$('.bxslider').bxSlider({
startSlide: 0,
infiniteLoop: true,
});
});
我不确定如何提取查询字符串值,然后将其值插入startSlide.任何帮助将不胜感激.
I am not sure how to pull the query string value and then insert its value into the startSlide. Any help would be appreciated.
推荐答案
您可以从window.location.search
手动提取ID.或者使用其中带有deparam
函数的库.
You can either manually extract id from window.location.search
. Or use some library with deparam
function in it.
$(function(){
var search = window.location.search.substr(1),
params = $.map(search.split('&'), function(item) {
var matches = item.split('=');
return { name: matches[0], value: matches[2]};
}),
id = parseInt($.grep(params, function(param){
return param.name === 'id';
}).value, 10);
$('.bxslider').bxSlider({
startSlide: id - 1, //zero based
infiniteLoop: true,
});
})
这篇关于查询字符串以控制BXSlider startSlide的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文