Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/apache-spark/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用jQuery选项卡时出现window.location.hash问题_Javascript_Jquery_Html - Fatal编程技术网

Javascript 使用jQuery选项卡时出现window.location.hash问题

Javascript 使用jQuery选项卡时出现window.location.hash问题,javascript,jquery,html,Javascript,Jquery,Html,我在一个页面上有三个表单,在三个单独的选项卡中。在使用jQuery选项卡时,每个选项卡都被唯一标识为必要的 当我提交表单时,我会显示一条感谢信息,然后用三个选项卡将页面重定向回初始页面 在将位置设置回原始页面时,我希望它自动转到提交表单的选项卡 我尝试了以下方法: setTimeout(setToDefault,2000); function setToDefault() { window.location = window.location.hash="tabs-28"; } 这会更

我在一个页面上有三个表单,在三个单独的选项卡中。在使用jQuery选项卡时,每个选项卡都被唯一标识为必要的

当我提交表单时,我会显示一条感谢信息,然后用三个选项卡将页面重定向回初始页面

在将位置设置回原始页面时,我希望它自动转到提交表单的选项卡

我尝试了以下方法:

setTimeout(setToDefault,2000); 

function setToDefault()
{  window.location = window.location.hash="tabs-28";  }

这会更改url栏中的地址,但页面不会移动到任何地方。有什么想法吗?

运行该JavaScript时,您不清楚自己是否已经在“原始”页面上,但您正在尝试设置window.location而没有URL,因此我假设您已经在正确的页面上,并且正在尝试显示另一个选项卡:

如果使用jQuery选项卡,请设置历史记录的哈希值,然后使用select方法:

如果您不在包含选项卡的原始页面上,则在“谢谢”页面上:

window.location.hash = "originalpage.html#tabs-28";
然后回到“原始”页面:

jQuery(function({ 
    if (window.location.hash != '') {
        var myTabElement = jQuery('#whateverTabElementIs'),
            index = ???; 
            // ??? = however you figure the index based on current window.location.hash
        myTabElement.tabs("select", index);
    } 
}));
或者,如果您想在初始化tabs元素时

jQuery( "#whateverTabElementIs" ).tabs({ selected: ??? });
// ??? = however you figure the index based on current window.location.hash

可能在设置哈希后添加location.reload?
jQuery( "#whateverTabElementIs" ).tabs({ selected: ??? });
// ??? = however you figure the index based on current window.location.hash