gpt4 book ai didi

javascript - 如何创建动态选项卡内容

转载 作者:行者123 更新时间:2023-12-03 06:30:18 24 4
gpt4 key购买 nike

我的应用程序中有第一个选项卡,

我想知道当我点击我的按钮时是否可以创建一个新选项卡?

<html>
<head>
<title>How to Create dynamic tab content</title>

<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css">
<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>

<script>
$(document).ready(function() {
$('.nav-tabs > li > a').click(function(event){
event.preventDefault();//stop browser to take action for clicked anchor

//get displaying tab content jQuery selector
var active_tab_selector = $('.nav-tabs > li.active > a').attr('href');

//find actived navigation and remove 'active' css
var actived_nav = $('.nav-tabs > li.active');
actived_nav.removeClass('active');

//add 'active' css into clicked navigation
$(this).parents('li').addClass('active');

//hide displaying tab content
$(active_tab_selector).removeClass('active');
$(active_tab_selector).addClass('hide');

//show target tab content
var target_tab_selector = $(this).attr('href');
$(target_tab_selector).removeClass('hide');
$(target_tab_selector).addClass('active');
});
});
</script>
<style>
/** Start: to style navigation tab **/
.nav {
margin-bottom: 18px;
margin-left: 0;
list-style: none;
}

.nav > li > a {
display: block;
}

.nav-tabs{
*zoom: 1;
}

.nav-tabs:before,
.nav-tabs:after {
display: table;
content: "";
}

.nav-tabs:after {
clear: both;
}

.nav-tabs > li {
float: left;
}

.nav-tabs > li > a {
padding-right: 12px;
padding-left: 12px;
margin-right: 2px;
line-height: 14px;
}

.nav-tabs {
border-bottom: 1px solid #ddd;
}

.nav-tabs > li {
margin-bottom: -1px;
}

.nav-tabs > li > a {
padding-top: 8px;
padding-bottom: 8px;
line-height: 18px;
border: 1px solid transparent;
-webkit-border-radius: 4px 4px 0 0;
-moz-border-radius: 4px 4px 0 0;
border-radius: 4px 4px 0 0;
}

.nav-tabs > li > a:hover {
border-color: #eeeeee #eeeeee #dddddd;
}

.nav-tabs > .active > a,
.nav-tabs > .active > a:hover {
color: #555555;
cursor: default;
background-color: #ffffff;
border: 1px solid #ddd;
border-bottom-color: transparent;
}

li {
line-height: 18px;
}

.tab-content.active{
display: block;
}

.tab-content.hide{
display: none;
}


/** End: to style navigation tab **/
</style>
</head>
<body>
<div>
<ul class="nav nav-tabs">
<li class="active">
<a href="#tab1">Show Tab 1</a>
</li>
</ul>
</div>
<section id="tab1" class="tab-content active">
<div>
<a href="#popupLogin" data-rel="popup" data-position-to="window" class="ui-btn ui-corner-all ui-shadow ui-btn-inline ui-icon-check ui-btn-icon-left ui-btn-a" data-transition="pop">Open</a>
</div>
<div data-role="popup" id="popupLogin" data-theme="a" class="ui-corner-all">
    <form>
        <div style="padding:10px 20px;">
            <h3>Create new tab</h3>
            <button type="submit" class="ui-btn ui-corner-all ui-shadow ui-btn-b ui-btn-icon-left ui-icon-check">Create Me !</button>
        </div>
    </form>
</div>
</section>
</body>
</html>

最佳答案

使用追加来构建您的选项卡

<html>

<head>
<title>How to Create dynamic tab content</title>

<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css">
<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>

<script>
$(document).ready(function() {
$('.nav-tabs > li > a').click(function(event) {
event.preventDefault(); //stop browser to take action for clicked anchor

//get displaying tab content jQuery selector
var active_tab_selector = $('.nav-tabs > li.active > a').attr('href');

//find actived navigation and remove 'active' css
var actived_nav = $('.nav-tabs > li.active');
actived_nav.removeClass('active');

//add 'active' css into clicked navigation
$(this).parents('li').addClass('active');

//hide displaying tab content
$(active_tab_selector).removeClass('active');
$(active_tab_selector).addClass('hide');

//show target tab content
var target_tab_selector = $(this).attr('href');
$(target_tab_selector).removeClass('hide');
$(target_tab_selector).addClass('active');
});
$('[type="submit"]').click(function(e) {

e.preventDefault();
$('.nav').append('<li><a href="#tab2">show tab2</a></li>');
$('body').append('<section id="tab2" class="tab-content">tab2</section>')
});
});
</script>
<style>
/** Start: to style navigation tab **/
.nav {
margin-bottom: 18px;
margin-left: 0;
list-style: none;
}
.nav > li > a {
display: block;
}
.nav-tabs {
*zoom: 1;
}
.nav-tabs:before,
.nav-tabs:after {
display: table;
content: "";
}
.nav-tabs:after {
clear: both;
}
.nav-tabs > li {
float: left;
}
.nav-tabs > li > a {
padding-right: 12px;
padding-left: 12px;
margin-right: 2px;
line-height: 14px;
}
.nav-tabs {
border-bottom: 1px solid #ddd;
}
.nav-tabs > li {
margin-bottom: -1px;
}
.nav-tabs > li > a {
padding-top: 8px;
padding-bottom: 8px;
line-height: 18px;
border: 1px solid transparent;
-webkit-border-radius: 4px 4px 0 0;
-moz-border-radius: 4px 4px 0 0;
border-radius: 4px 4px 0 0;
}
.nav-tabs > li > a:hover {
border-color: #eeeeee #eeeeee #dddddd;
}
.nav-tabs > .active > a,
.nav-tabs > .active > a:hover {
color: #555555;
cursor: default;
background-color: #ffffff;
border: 1px solid #ddd;
border-bottom-color: transparent;
}
li {
line-height: 18px;
}
.tab-content.active {
display: block;
}
.tab-content.hide {
display: none;
}
/** End: to style navigation tab **/
</style>
</head>

<body>
<div>
<ul class="nav nav-tabs">
<li class="active">
<a href="#tab1">Show Tab 1</a>
</li>
</ul>
</div>
<section id="tab1" class="tab-content active">
<div>
<a href="#popupLogin" data-rel="popup" data-position-to="window" class="ui-btn ui-corner-all ui-shadow ui-btn-inline ui-icon-check ui-btn-icon-left ui-btn-a" data-transition="pop">Open</a>
</div>
<div data-role="popup" id="popupLogin" data-theme="a" class="ui-corner-all">

<form>

<div style="padding:10px 20px;">

<h3>Create new tab</h3>

<button type="submit" class="ui-btn ui-corner-all ui-shadow ui-btn-b ui-btn-icon-left ui-icon-check">Create Me !</button>
</div>
</form>
</div>
</section>
</body>

</html>

关于javascript - 如何创建动态选项卡内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38478099/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com