Javascript jQuery选项卡:如何创建指向特定选项卡的链接
您好,我已经找到了这个主题: 但这并不能解决我的问题 这是我的代码:Javascript jQuery选项卡:如何创建指向特定选项卡的链接,javascript,php,jquery,url,hyperlink,Javascript,Php,Jquery,Url,Hyperlink,您好,我已经找到了这个主题: 但这并不能解决我的问题 这是我的代码: $(document).ready(function() { //Default Action $(".tab_content").hide(); //Hide all content $("ul.tabs li:first").addClass("active").show(); //Activate first tab $(".tab_content:first").show(); //Show first tab co
$(document).ready(function() {
//Default Action
$(".tab_content").hide(); //Hide all content
$("ul.tabs li:first").addClass("active").show(); //Activate first tab
$(".tab_content:first").show(); //Show first tab content
//On Click Event
$("ul.tabs li").click(function() {
$("ul.tabs li").removeClass("active"); //Remove any "active" class
$(this).addClass("active"); //Add "active" class to selected tab
$(".tab_content").hide(); //Hide all tab content
var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
$(activeTab).fadeIn(); //Fade in the active content
e.preventDefault();
yInitPos = $(window).scrollTop();
// On ajoute le hash dans l'url.
window.location.hash = $(this).attr("href");
return false;
});
});
我无法访问具有以下链接的选项卡:
你能帮我吗?谢谢尝试下面的脚本,只需对//on ajute le hash dans进行一次更改
Try this below script, just made once change to the // on ajoute le hash dans
and added some code below the click function
$(document).ready(function() {
//Default Action
$(".tab_content").hide(); //Hide all content
$("ul.tabs li:first").addClass("active").show(); //Activate first tab
$(".tab_content:first").show(); //Show first tab content
//On Click Event
$("ul.tabs li").click(function(e) {
$("ul.tabs li").removeClass("active"); //Remove any "active" class
$(this).addClass("active"); //Add "active" class to selected tab
$(".tab_content").hide(); //Hide all tab content
var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
$(activeTab).fadeIn(); //Fade in the active content
e.preventDefault();
yInitPos = $(window).scrollTop();
// On ajoute le hash dans l'url.
// $(this) below will be <li> tag, so you have to get to the children <a> tag with href attr
window.location.hash = $(this).children().attr("href");
return false;
});
// the code below gets the hash(#) value from the url and finds the link with a href of this # value and triggers it
var tabId = window.location.hash;
console.log(tabId);
if(tabId !== "")
{
$(".tabs").find('a[href='+tabId+']').click();
}
});
并在单击功能下方添加了一些代码
$(文档).ready(函数(){
//默认动作
$(“.tab_content”).hide();//隐藏所有内容
$(“ul.tabs li:first”).addClass(“active”).show();//激活第一个选项卡
$(“.tab_content:first”).show();//显示第一个选项卡内容
//点击事件
$(“ul.tabs li”)。单击(功能(e){
$(“ul.tabs li”).removeClass(“active”);//删除任何“active”类
$(this).addClass(“active”);//将“active”类添加到所选选项卡
$(“.tab_content”).hide();//隐藏所有选项卡内容
var activeTab=$(this).find(“a”).attr(“href”);//查找rel属性值以标识活动选项卡+内容
$(activeTab).fadeIn();//淡入活动内容
e、 预防默认值();
yInitPos=$(window.scrollTop();
//在我的网站上。
//下面的$(这)将是标记,因此您必须使用href attr访问children标记
window.location.hash=$(this.children().attr(“href”);
返回false;
});
//下面的代码从url获取散列(#)值,并找到带有此#值的href的链接并触发它
var tabId=window.location.hash;
console.log(tabId);
如果(tabId!==“”)
{
$(“.tabs”).find('a[href='+tabId+'])。单击();
}
});
尝试下面的脚本,只需更改一下//on ajute le hash dans即可
并在单击功能下方添加了一些代码
$(文档).ready(函数(){
//默认动作
$(“.tab_content”).hide();//隐藏所有内容
$(“ul.tabs li:first”).addClass(“active”).show();//激活第一个选项卡
$(“.tab_content:first”).show();//显示第一个选项卡内容
//点击事件
$(“ul.tabs li”)。单击(功能(e){
$(“ul.tabs li”).removeClass(“active”);//删除任何“active”类
$(this).addClass(“active”);//将“active”类添加到所选选项卡
$(“.tab_content”).hide();//隐藏所有选项卡内容
var activeTab=$(this).find(“a”).attr(“href”);//查找rel属性值以标识活动选项卡+内容
$(activeTab).fadeIn();//淡入活动内容
e、 预防默认值();
yInitPos=$(window.scrollTop();
//在我的网站上。
//下面的$(这)将是标记,因此您必须使用href attr访问children标记
window.location.hash=$(this.children().attr(“href”);
返回false;
});
//下面的代码从url获取散列(#)值,并找到带有此#值的href的链接并触发它
var tabId=window.location.hash;
console.log(tabId);
如果(tabId!==“”)
{
$(“.tabs”).find('a[href='+tabId+'])。单击();
}
});
您知道我们无法跟踪该链接,对吗?链接问题中的答案如何没有帮助?它在这里包含解决方案-var-activeTab=$(this.find(“a”).attr(“href”)$(activeTab.show()代码>在上面的代码中,您没有使用您引用的主题的“解决方案”。。。这可能会有帮助。同时提供您的html代码,以便我们能够快速提供帮助。我只是在之后才这样做,提前谢谢。您知道我们无法跟踪该链接,对吗?链接问题中的答案如何没有帮助?它在这里包含解决方案-var-activeTab=$(this.find(“a”).attr(“href”)$(activeTab.show()代码>在上面的代码中,您没有使用您引用的主题的“解决方案”。。。这可能会有帮助。同时提供您的html代码,以便我们能够快速提供帮助。我只是在之后才做,提前谢谢。哦,谢谢!这就是工作,与我在链接中给出的解决方案有什么不同?将这个新的添加到您的代码var tabId=window.location.hash;console.log(tabId);if(tabId!==“”){$(“.tabs”).find('a[href='+tabId+'])。单击();}并更改行,使其获得正确的元素//在一个路径上。window.location.hash=$(this.children().attr(“href”);哦,好的,谢谢,我被困了几个小时。祝你今天愉快。哦,谢谢你!这就是工作,与我在链接中给出的解决方案有什么不同?将这个新的添加到您的代码var tabId=window.location.hash;console.log(tabId);if(tabId!==“”){$(“.tabs”).find('a[href='+tabId+'])。单击();}并更改行,使其获得正确的元素//在一个路径上。window.location.hash=$(this.children().attr(“href”);哦,好的,谢谢,我被困了几个小时。祝您今天过得愉快。