[样式]针对<span>标签选前和选中后的状态改变

CSS与JS实现筛选按钮
本文介绍了一种使用CSS和JavaScript实现动态筛选条件的方法。通过简单的HTML结构配合样式和脚本,可以创建交互式的筛选按钮,当点击按钮时,不仅会改变按钮的外观,还能根据选择的状态触发不同的行为。

选中前为"状态",选中后为"★状态"

html代码及js方法如下

<pre name="code" class="html"><span style="white-space:pre">		</span>.sctj{
			border:1px dotted #640000;
			background: #F7F9FC;
			margin-top:5px!important; 
			color:#000;
			padding:5px;
			margin-left:10px;
			white-space: nowrap;
			cursor: pointer;
		}
		
		.sctj:hover{
			border:1px solid #640000;
			background: #FD7F88;
		} 



<div class="search_sk" >
<span style="white-space:pre">	</span>筛选条件>>
	<span id="WQS" class="sctj" onclick="cjsxtj('WQS','未签收')" data-start="0">未签收</span>
	<span id="YQS" class="sctj" onclick="cjsxtj('YQS','已签收')" data-start="0">已签收</span>
	<span id="WFK" class="sctj" onclick="cjsxtj('WFK','未反馈')" data-start="0">未反馈</span>
	<span id="YFK" class="sctj" onclick="cjsxtj('YFK','已反馈')" data-start="0">已反馈</span>
</div>
<pre name="code" class="javascript">function cjsxtj(id,text){
	var inputValue = $("#searchInput").val();
	var ids=['WQS','YQS','WFK','YFK'];
	var start=$('#'+id).data().start;
	if(start==1){	//原来是选中状态
		var obj_html=$('#'+id).html();
		var html=new String(obj_html);
		$('#'+id).html(html.substring(1));
		$('#'+id).css('background-color','');
		$('#'+id).data({start:0});
		getRW(userName,XZRWID,inputValue,'');
	}else{//未选中
		for(var i=0;i<ids.length;i++){
			var _id=ids[i];
			var _start=$('#'+_id).data().start;
			if(_start==1){
				var html2=new String($('#'+_id).html());
				$('#'+_id).html(html2.substring(1));
				$('#'+_id).data({start:0});
			}
			$('#'+_id).css('background-color','');
		}
		var obj_html=$('#'+id).html();
		var html=new String(obj_html);
		$('#'+id).html('★'+html);
		$('#'+id).css('background-color','#FD7F88');
		$('#'+id).data({start:1});
		getRW(userName,XZRWID,inputValue,text);
	}
	
}






<template> <!-- 分析报告 --> <div class="analysis-report"> <div class="analysis-report-body"> <tableFormworkPage> <template v-slot:btnBox> <div class="report-top"> <a-button type="primary" style="margin-right: 12px">{{ $t('批量下载') }}</a-button> <a-checkbox v-model="checkAll" :indeterminate="indeterminate" @change="onCheckAllChange"> {{ $t('全') }} </a-checkbox> </div> </template> <template v-slot:serchBox> <div class="input-box"> <div class="search-items"> <span class="search-name">{{ $t('报表名称') }}:</span> <a-input allow-clear placeholder="报表名称" style="width: 200px" v-model="weeklyName"></a-input> </div> <div class="search-items"> <span class="search-name">{{ $t('统计时间段') }}:</span> <a-range-picker @change="timerChange" format="YYYY-MM-DD" v-model="timer" /> </div> <div class="searchButton"> <a-button @click="onWeightConfig" type="primary"> {{ $t('权重配置') }} </a-button> <a-button @click="getSearchVal" type="primary"> {{ $t('common.scf.btn.search') }} </a-button> <a-button @click="resetInputValue"> {{ $t('common.scf.btn.reset') }} </a-button> </div> </div> </template> <template v-slot:tableBox> <div class="card-container"> <div class="card-box" v-for="(item, index) in dataList" :key="index"> <div class="card" :class="{ cardIsCheck: item.checkbox }"> <div class="card-content"> <div class="header"> <div class="checkbox-box"> <a-checkbox v-model="item.checkbox" @change="onChange"></a-checkbox> </div> <div class="downloadIcon" @click="onDownload(item)"> <i class="ico-download_center"></i> </div> </div> <div class="body"></div> <div class="bottom"></div> </div> </div> </div> </div> </template> <template v-slot:paginationBox> <div v-if="dataList.length"> <my-pagination style="padding: 0" :showSizeChanger="true" :pageIndex.sync="pagination.currentPage" @changePage="changePage" :pageSize="pagination.pageSize" :total="pagination.totalRows" @onShowSizeChange="onShowSizeChange" ></my-pagination> </div> </template> </tableFormworkPage> </div> <!-- 编辑权重 --> <edit-weight ref="editWeight"></edit-weight> </div> </template> <script> import EditWeight from './components/editWeight.vue' import tableFormworkPage from '@/components/scfComponents/tableFormwork/tableFormworkPage' import myPagination from '@/components/scfComponents/paginationFormwork/myPagination.vue' export default { components: { EditWeight, myPagination, tableFormworkPage, }, data() { return { checkAll: false, checkedList: [], dataList: [ { checkbox: false }, { checkbox: true }, { checkbox: false }, { checkbox: false }, { checkbox: false }, { checkbox: false }, { checkbox: false }, { checkbox: false }, { checkbox: false }, { checkbox: false }, { checkbox: false }, { checkbox: false }, { checkbox: false }, { checkbox: false }, { checkbox: false }, { checkbox: false }, { checkbox: false }, { checkbox: false }, { checkbox: false }, { checkbox: false }, { checkbox: false }, { checkbox: false }, { checkbox: false }, { checkbox: false }, { checkbox: false }, { checkbox: false }, { checkbox: false }, { checkbox: false }, { checkbox: false }, { checkbox: false }, { checkbox: false }, { checkbox: false }, { checkbox: false }, { checkbox: false }, { checkbox: false }, { checkbox: false }, { checkbox: false }, { checkbox: false }, { checkbox: false }, { checkbox: false }, { checkbox: false }, { checkbox: false }, { checkbox: false }, { checkbox: false }, { checkbox: false }, { checkbox: false }, { checkbox: false }, { checkbox: false }, { checkbox: false }, { checkbox: false }, { checkbox: false }, { checkbox: false }, { checkbox: false }, { checkbox: false }, { checkbox: false }, { checkbox: false }, { checkbox: false }, { checkbox: false }, { checkbox: false }, { checkbox: false }, { checkbox: false }, { checkbox: false }, { checkbox: false }, { checkbox: false }, ], indeterminate: false, pagination: { pageSize: 10, currentPage: 1, totalRows: 0, }, } }, mounted() {}, methods: { // 全 onCheckAllChange(e) { this.dataList.forEach(el => { el.checkbox = e.target.checked }) if (this.checkAll) { this.indeterminate = false } }, // 单 onChange() { let checkedList = this.dataList.filter(e => e.checkbox) || [] this.indeterminate = !!checkedList.length && checkedList.length < this.dataList.length this.checkAll = checkedList.length === this.dataList.length }, // 返回被选中的卡片 getDataListIsCheck() { return this.dataList.filter(e => e.checkbox) || [] }, onWeightConfig() { this.$refs.editWeight.openModal() }, }, } </script> <style lang="less" scoped> .analysis-report { width: 100%; height: 100%; box-sizing: border-box; padding: 0 20px; .analysis-report-body { width: 100%; position: relative; height: calc(100% - 30px); } .report-top { display: flex; align-items: center; } .input-box { display: flex; flex-direction: row; align-items: center; .search-items { display: flex; flex-direction: row; align-items: center; margin-left: 12px; .search-name { min-width: 50px; max-width: 100px; margin-right: 4px; } .search-input { width: 200px; } } .searchButton { display: flex; button { margin-left: 12px; } } } .card-container { width: 100%; display: flex; flex-wrap: wrap; .card-box { width: 20%; height: 120px; padding: 5px; position: relative; .card { width: 100%; height: 100%; padding: 0 16px; border-radius: 6px; border: 1px solid #e6e9ed; .cardIsCheck { border: 1px solid #1c79f4; } .header { display: flex; align-items: center; justify-content: space-between; } } .card:hover { border: 1px solid #1c79f4; } } } } </style> 代码评审
07-26
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值