87,903
社区成员
发帖
与我相关
我的任务
分享
<script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.js"></script>
<style>
.tab-container {
width: 100%;
}
.tab-container .tab-head {
line-height: 40px;
clear: both;
}
.tab-container .tab-content {
padding: 0px;
margin: 0px;
width: 800px;
height: 600px;
clear: both;
}
.tab-container .tab-head-item {
float: left;
}
.tab-container .tab-head-item.active {
background: lightblue;
color: #fff;
}
.tab-container .tab-head label {
line-height: 40px;
padding: 0px;
margin: 0 0 0 0;
width: 100px;
height: 30px;
font-weight: bold;
color: #999;
}
.tab-container .tab-content .tab-panel {
display: none;
}
.tab-container .tab-content .tab-panel.active {
display: block;
}
.tab-container .tab-content .tab-panel .text_bedid {
position: relative;
left: 35px;
top: -30px;
font: bold;
color: white;
}
.tab-container .tab-content .tab-panel .text_person_name {
position: relative;
left: 85px;
top: -51px;
font: bold;
color: white;
}
</style>
<body>
<div class="tab-container">
<div class="tab-head"></div>
<div class="tab-content"></div>
</div>
<script>
// 添加tab
var data = [
{
id: 'tab_id_1',
type: 'tab_type_1',
title: 'tab_title_1',
person_info: {
name: 'xxx'
},
heart_info: {
text: '心跳xxx'
},
breath_info: {
text: '呼吸xxx'
},
bedstat_info: {
id: '0001',
text: '着床xxx'
},
comment: '备注',
alarm_info: {
text: '警告xxx'
}
},
{
id: 'tab_id_2',
type: 'tab_type_2',
title: 'tab_title_2',
person_info: {
name: 'xxx'
},
heart_info: {
text: '心跳xxx'
},
breath_info: {
text: '呼吸xxx'
},
bedstat_info: {
id: '0001',
text: '着床xxx'
},
comment: '备注',
alarm_info: {
text: '警告xxx'
}
}
]
var tabContainer = $('.tab-container')
function addTab(data) {
var tabHead = ''
var tabContent = ''
data.forEach((item, index) => {
tabHead += `<div class="tab-head-item">
<label for="tab_${item.id}">${item.title}</label>
<input id="tab_${item.id}" name="tabs-two" type="radio">
</div>`
tabContent += `<div class="tab-panel" id="tab_${item.id}">${item.title}
<div class="item_personnal_info">
<div class="i_personnal_info_title">个人信息</div>
<img src="/img/ic_account_child_32px.png" />
<p class="item_pf_title_img text_bebid">${item.bedstat_info.id}</p>
<p class="item_pf_title_img text_person_name">${item.person_info.name}</p>
<img class="item_pf_title_img" src="/img/ic_wechat_32px.png" />
<img class="item_pf_title_img edit" src="/img/ic_mode_edit_32px.png" pid="tab_${item.id}" />
<img class="item_pf_title_img remove" src="/img/ic_mode_edit_32px.png" pid="tab_${item.id}" />
</div>
<div class="item_pf_info">
<img class="box_32px_32px" src="/img/ic_heart_rate_48px.png">
<h3 class="text_black_absolute_5px_40px">心跳信息</h3>
<div class="heart">
${item.heart_info}
</div>
</div>
<div class="item_pf_info">
<img class="box_32px_32px" src="/img/ic_breath_48px.png">
<h3 class="text_black_absolute_5px_40px breath">呼吸信息</h3>
<div class="breath">
${item.breath_info}
</div>
</div>
<div class="item_pf_info">
<img class="box_32px_32px" src="/img/ic_bed_48px.png">
<h3 class="text_black_absolute_5px_40px">着床信息</h3>
<div class="bedstat">
${item.bedstat_info}
</div>
</div>
<div class="item_pf_info">
<h3 class="comment">备注信息</h3>
<div class="comment">${item.comment}</div>
</div>
<div class="alarm_info">
<img class="box_32px_32px" src="/img/ic_report_problem.png">
<h2 class="text_black_absolute_5px_40px">报警信息</h2>
<div class="alarm_info">
${item.alarm_info}
</div>
</div>
</div>`
})
$('.tab-head').html(tabHead)
$('.tab-content').html(tabContent)
$('.tab-head').find('.tab-head-item').eq(0).addClass('active')
$('.tab-head').find('input').eq(0).attr('checked', 'checked')
$('.tab-content').find('.tab-panel').eq(0).addClass('active')
}
// 编辑
tabContainer.on('click', '.edit', function () {
var el = $(this)
console.log('--编辑--')
console.log(el.attr('pid'))
alert('编辑:::'+el.attr('pid'))
})
// 删除
tabContainer.on('click', '.remove', function () {
var el = $(this)
console.log('--删除--')
console.log(el.attr('pid'))
alert('删除:::'+el.attr('pid'))
})
// tab切换
tabContainer.on('change', '.tab-head-item', function() {
var el = $(this)
console.log($(this).index())
$('.tab-head').find('.tab-head-item').removeClass('active').eq(el.index()).addClass('active')
$('.tab-content').find('.tab-panel').removeClass('active').eq(el.index()).addClass('active')
})
addTab(data)
</script>
</body>