jQuery 选项卡。 。 。我需要做这一切! (鼠标悬停,从选项卡单击导航并根据页面选择选项卡)
在阅读了所有 jQuery 文档、SO 问题和随机博客后,我一直无法找到问题的答案。
目前我正在将 Coldfusion 站点移植到 .Net 站点。在我的网站母版页中,我拥有所有导航元素,因为它只是网站的管理部分。
导航 html 代码:
<div id="tabs" class="basictab">
<ul>
<li><a href="#fragment-1"><span>Insurance Plans</span></a></li>
<li><a href="#fragment-2"><span>Mini-Sites</span></a></li>
<li><a href="#fragment-3"><span>Independent Sites</span></a></li>
<li><a href="#fragment-4"><span>Tools</span></a></li>
</ul>
<div id="fragment-1" class="tabcontainer">
<nav:insurance runat="server" ID="ins1" Visible="true" />
</div>
<div id="fragment-2" class="tabcontainer">
<nav:mini runat="server" ID="mini1" Visible="true" />
</div>
<div id="fragment-3" class="tabcontainer">
<div>
<div id="fragment-4" class="tabcontainer">
<nav:tools runat="server" ID="tools2" Visible="true" />
</div>
</div>
在我的标题我的主页中:
<script type="text/javascript" >
$(document).ready(function(){
$("#tabs").tabs({event: 'mouseover'});
});
</script>
您可以看出,该网站有 4 个(实际上是 3 个)主要部分:保险计划、迷你网站、独立网站和工具。在这些部分的每一部分下都有几个页面(所有页面都使用相同的母版页)。
鼠标悬停功能效果很好,div 按预期隐藏和显示。我遇到的问题是在每个页面的每个部分上都选择了 div id="fragment-1"
。 (例如,在“工具”部分中 div id="fragment-4"
时,我需要选择它。我尝试添加 $('#tabs').tabs ('option', 'selected', 3);
在 .aspx 页面的头部和母版页中进行测试,我收到一个错误。 ').tabs('option', 'selected', 3); 到 $(document).ready 函数中,它仍然在 .aspx 页面和母版页中抛出错误
。上述问题的解决方案: 放置
<script type="text/javascript" >
$(document).ready(function(){
var $tabs = $("#tabs").tabs({event: 'mouseover'});
$tabs.tabs("select", 3);
});
</script>
在“3”部分中的页面末尾允许默认选择适当的选项卡。
删除:
<script type="text/javascript" >
$(document).ready(function(){
var $tabs = $("#tabs").tabs({event: 'mouseover'});
});
</script>
同时从母版页的标题中
。最重要的是,我需要可单击的选项卡进行导航(不是 ajax 加载,但我需要用户在单击选项卡时转到不同的页面。我认为这类似于窗口.location()。
有人可以帮助我完成第二部分吗?
After reading through all of the jQuery doc, SO questions, and random blogs, I have been unable to find an answer to my problem.
Currently I am porting a Coldfusion Site to a .Net site. In my masterpage for the site I have all of my navigation elements as it is just the Administrative portion of the site.
The navigation html code:
<div id="tabs" class="basictab">
<ul>
<li><a href="#fragment-1"><span>Insurance Plans</span></a></li>
<li><a href="#fragment-2"><span>Mini-Sites</span></a></li>
<li><a href="#fragment-3"><span>Independent Sites</span></a></li>
<li><a href="#fragment-4"><span>Tools</span></a></li>
</ul>
<div id="fragment-1" class="tabcontainer">
<nav:insurance runat="server" ID="ins1" Visible="true" />
</div>
<div id="fragment-2" class="tabcontainer">
<nav:mini runat="server" ID="mini1" Visible="true" />
</div>
<div id="fragment-3" class="tabcontainer">
<div>
<div id="fragment-4" class="tabcontainer">
<nav:tools runat="server" ID="tools2" Visible="true" />
</div>
</div>
In my header OF MY MASTER PAGE:
<script type="text/javascript" >
$(document).ready(function(){
$("#tabs").tabs({event: 'mouseover'});
});
</script>
The site as you can tell has 4 (well 3 really) major sections: Insurance Plans, Mini-Sites, Independent Sites and Tools. Under each one of these sections there are several pages (all which use the same master page).
The mouse over function works great, the divs hide and display as expected. The problems that I am having is that div id="fragment-1"
is selected on every page for every section. (As an example, when in the Tools Section, div id="fragment-4"
, I need it to be selected. I have tried adding $('#tabs').tabs('option', 'selected', 3);
in both the head of the .aspx page and in the masterpage for testing and I get an error. Additionally I have tried throwing $('#tabs').tabs('option', 'selected', 3);
into the $(document).ready function, and it still throws an error, both within the .aspx page and the masterpage.
Solution to above problem:
Placing
<script type="text/javascript" >
$(document).ready(function(){
var $tabs = $("#tabs").tabs({event: 'mouseover'});
$tabs.tabs("select", 3);
});
</script>
at the end of a page in section "3" allows the appropriate tab to be default selected.
While removing:
<script type="text/javascript" >
$(document).ready(function(){
var $tabs = $("#tabs").tabs({event: 'mouseover'});
});
</script>
from the header of the master page.
To top it all off, I need the tabs to be clickable to navigate (not an ajax load, but I need for the user, when clicking on the tab to be taken to a different page. I would assume this would be analogous to window.location().
Can anyone please help with the second part? I am a jQuery n00b.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
对于第一部分,您可以按照 karim79 的建议进行操作,并尝试找出它是什么页面并相应地设置默认值。
这是在设置选项卡之前进行的:
然后您可以执行以下操作:
现在回答第二个问题:
如果我理解正确的话,您希望人们单击选项卡的名称并被重定向?
这可以通过绑定点击事件来完成。
您必须首先为导航中的每个 A 分配一个 ID:
然后创建一个函数,该函数将采用该 ID 并决定将用户发送到哪里:
然后将其绑定到 a:(
不过我没有测试任何这些:P )
For the first part, you could do what karim79 suggested and try to figure out what page it is and set the default accordingly.
This goes before setting the tabs:
then you can do:
Now for the second question:
If I understood correctly, you want people to click on the tabs' names and be redirected?
This can be done by binding the click event.
You must first assign an ID to each A in your navigation:
Then make a function that will take that ID and decide where to send the user:
And then bind it to the a:
(I didn't test any of this though :P)
你有没有尝试过:
Have you tried: