[英]Loading tab by default in jQuery tab script
I have a jQuery tab script that gets content from a PHP file defined by the link and parses it to a div element.我有一个 jQuery 选项卡脚本,它从链接定义的 PHP 文件中获取内容并将其解析为 div 元素。 When a user selects a tab, it turns bold.
当用户选择一个选项卡时,它会变为粗体。 However, currently when the script is loaded up, a tab is not selected by default.
但是,当前加载脚本时,默认情况下不选择选项卡。 My question is how can I load up a certain tab and it's contents by default and show that the tab is selected with my current code?
我的问题是如何加载某个选项卡及其默认内容并显示该选项卡是用我当前的代码选择的?
This is my current jQuery code:这是我当前的 jQuery 代码:
function load(url){
$.ajax({
url:url,
success:function(message){
$("#content").html(message);
}
});
}
$(document).ready(function(){
$("[id]").click(function(){
type=$(this).attr("id");
url=""+type+".php";
$("[id]").removeClass("selected");
$("#"+type).addClass("selected");
load(url);
return false;
});
});
This is my HTML code:这是我的 HTML 代码:
<ul>
<li><a id="tab1" href="javascript:void(null);">Tab1</a></li>
<li><a id="tab2" href="javascript:void(null);">Tab2</a></li>
<li><a id="tab3" href="javascript:void(null);">Tab3</a></li>
</ul>
Trigger the click event of the tab you want to load: eg -触发要加载的选项卡的点击事件:例如 -
$(document).ready(function(){
$("[id]").click(function(){
type=$(this).attr("id");
url=""+type+".php";
$("[id]").removeClass("selected");
$("#"+type).addClass("selected");
load(url);
return false;
});
//load default tab
$("#tab1").click();
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.