,我不希望在没有消息时应用样式。
代码:
$( document ).ready(function() {
if($('.CP_CF_Container > span.msg-error').length){
$('.vertical-input').addClass('checkbox-fld-error')
}
});
CSS:
.checkbox-fld-error{border:1px solid red}
.CP_CF_Container{width:50%;background-color:#eee;padding:5px;}
.msg-error{color:red}
Html:
<div class="CP_CF_Container">
<div class="vertical-input">hello there</div>
<span class="msg-error" >Error</span>
</div>
<br>
<div class="CP_CF_Container">
<div class="vertical-input">hello there</div>
<span class="msg-error" >Error</span>
</div>
<br>
<div class="CP_CF_Container">
<div class="vertical-input">hello there</div>
</div>
您可以链接方法并使用
.prev()
或
.siblings()
$('.CP_CF_Container > span.msg-error')
.prev('.vertical-input')
.addClass('checkbox-fld-error');
Http://jsfiddle.net/hl9gp/
您还可以使用
.has()
返回/过滤具有指定元素的元素的方法:
$('.CP_CF_Container').has('span.msg-error')
.find('.vertical-input')
.addClass('checkbox-fld-error');
页面上的jQuery有点畸形:改变:
if($(this).('.CP_CF_Container > span.msg-error').length){
if($('.CP_CF_Container > span.msg-error').length){
http://jsfiddle.net/99tdr/5/
Datagrid.css
.ag-theme-alpine {
--ag-header-height: 48px;
--ag-header-foreground-color: #1a202c;
--ag-header-background-color: #f8fafc;
--ag-header-cell-hover-background-color: #f0f0f0;
--ag-row-hover-color: #fff1f2;
--ag-selected-row-background-color: rgba(190, 37, 51, 0.1);
--ag-font-size: 14px;
--ag-font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
sans-serif;
--ag-border-color: #e2e8f0;
--ag-secondary-border-color: #f0f0f0;
--ag-alpine-active-color: #be2533;
--ag-popup-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}
.grid-wrapper {
background: #f8fafc;
min-height: calc(100vh - 64px);
padding: 1.5rem;
}
.grid-container {
height: calc(100vh - 180px);
display: flex;
flex-direction: column;
background: white;
border-radius: 8px;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
padding: 1rem;
overflow: hidden;
}
.grid-container.loading {
position: relative;
}
.grid-container.loading::after {
content: "";
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(255, 255, 255, 0.7);
backdrop-filter: blur(2px);
z-index: 1;
pointer-events: none;
}
/* Custom Loading Overlay */
.ag-overlay-loading-center {
background: white !important;
padding: 20px 50px !important;
border-radius: 10px !important;
border: 1px solid #e0e0e0 !important;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1) !important;
color: #dc3545 !important;
font-weight: 500 !important;
}
/* Add loading animation */
.ag-overlay-loading-center::after {
content: "";
display: block;
width: 30px;
height: 30px;
margin: 10px auto 0;
border: 3px solid #dc3545;
border-top-color: transparent;
border-radius: 50%;
animation: spin 1s linear infinite;
}
@keyframes spin {
to {
transform: rotate(360deg);
}
}
.grid-toolbar {
flex-shrink: 0;
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 1rem;
gap: 1rem;
background-color: #f8fafc;
padding: 0.75rem;
border-radius: 6px;
}
.search-box {
position: relative;
flex: 1;
max-width: 480px;
}
.search-icon {
position: absolute;
left: 1rem;
top: 50%;
transform: translateY(-50%);
color: #94a3b8;
}
.quick-filter-input {
width: 100%;
padding: 0.875rem 1rem 0.875rem 2.75rem;
font-size: 0.9375rem;
border: 2px solid #e2e8f0;
border-radius: 12px;
background: white;
color: #1e293b;
transition: all 0.2s ease;
}
.quick-filter-input:focus {
border-color: #3b82f6;
box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.1);
outline: none;
}
.row-count {
display: flex;
flex-direction: column;
align-items: center;
background: #f1f5f9;
padding: 0.75rem 1.25rem;
border-radius: 12px;
min-width: 140px;
}
.count-label {
font-size: 0.75rem;
color: #64748b;
text-transform: uppercase;
letter-spacing: 0.05em;
margin-bottom: 0.25rem;
}
.count-number {
font-size: 1.25rem;
font-weight: 600;
color: #3b82f6;
}
.export-button {
padding: 8px 16px;
background-color: #be2533;
color: white;
border: none;
border-radius: 6px;
cursor: pointer;
display: flex;
align-items: center;
gap: 8px;
font-weight: 500;
transition: all 0.2s ease;
}
.export-button:hover {
background-color: #9c1d28;
}
.toolbar-actions {
display: flex;
align-items: center;
gap: 1rem;
}
.fullscreen-button {
padding: 8px 16px;
background-color: #4a5568;
color: white;
border: none;
border-radius: 6px;
cursor: pointer;
display: flex;
align-items: center;
gap: 8px;
font-weight: 500;
transition: all 0.2s ease;
}
.fullscreen-button:hover {
background-color: #2d3748;
}
.stats-container {
display: flex;
gap: 1rem;
background: white;
padding: 0.75rem 1rem;
border-radius: 6px;
border: 1px solid #e2e8f0;
}
.stat-item {
display: flex;
flex-direction: column;
align-items: center;
min-width: 120px;
}
.stat-label {
font-size: 0.75rem;
color: #64748b;
text-transform: uppercase;
letter-spacing: 0.05em;
margin-bottom: 0.25rem;
}
.stat-value {
font-size: 1rem;
font-weight: 600;
color: #be2533;
}
.status-success {
color: #16a34a;
}
.status-error {
color: #be2533;
}
.custom-loading-overlay {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 20px;
background: white;
border-radius: 10px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}
.loading-spinner {
width: 30px;
height: 30px;
border: 3px solid #dc3545;
border-top-color: transparent;
border-radius: 50%;
animation: spin 1s linear infinite;
margin-bottom: 10px;
}
.loading-message {
color: #dc3545;
font-weight: 500;
}
/* Add styles for full-screen mode */
.ag-theme-alpine.fullscreen {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
width: 100% !important;
height: 100vh !important;
z-index: 9999;
background: white;
margin: 0;
padding: 20px;
box-sizing: border-box;
}
/* Adjust grid container in fullscreen */
.fullscreen .grid-container {
height: 100vh;
padding: 16px;
display: flex;
flex-direction: column;
}
/* Keep toolbar visible and styled in fullscreen */
.fullscreen .grid-toolbar {
position: sticky;
top: 0;
z-index: 10000;
background: white;
padding: 16px;
margin-bottom: 16px;
border-bottom: 1px solid #e2e8f0;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
display: flex;
justify-content: space-between;
align-items: center;
gap: 1rem;
}
/* Ensure search box is visible and properly sized in fullscreen */
.fullscreen .search-box {
position: relative;
flex: 1;
max-width: 480px;
display: flex;
align-items: center;
}
/* Maintain other toolbar elements visibility */
.fullscreen .toolbar-actions,
.fullscreen .stats-container,
.fullscreen .row-count {
display: flex;
align-items: center;
}
/* Adjust the main grid area in fullscreen */
.fullscreen .ag-theme-alpine {
flex: 1;
height: calc(100vh - 120px) !important;
}
.stats-group {
display: flex;
gap: 1rem;
background: white;
padding: 0.75rem 1rem;
border-radius: 8px;
border: 1px solid #e2e8f0;
}
.stat-item {
display: flex;
flex-direction: column;
align-items: center;
min-width: 140px;
padding: 0.5rem 1rem;
background: #f8fafc;
border-radius: 6px;
}
.stat-label {
font-size: 0.75rem;
color: #64748b;
text-transform: uppercase;
letter-spacing: 0.05em;
margin-bottom: 0.25rem;
}
.stat-value {
font-size: 1.125rem;
font-weight: 600;
color: #1a202c;
}
.stat-item:first-child .stat-value {
color: #3b82f6; /* Blue for total count */
}
.stat-item:last-child .stat-value {
color: #10b981; /* Green for filtered count */
}