특정 CSS 클래스가 적용되지 않은보기에서 모든 레이블을 선택하고 싶습니다.
.ondemand-field[readonly]
{
color: #848284;
background-color:#FFFFFF;
}
<table>
<tr>
<td class="display-label">@Html.LabelFor(t => t.ProductId, new { @class = "ondemand-field" })</td>
<td class="display-field">@Html.DisplayFor(t => t.ProductId)</td>
</tr>
<tr>
<td class="display-label">@Html.LabelFor(t => t.ISBN)</td>
<td class="display-field">@Html.DisplayFor(t => t.ISBN)</td>
</tr>
<tr>
<td class="display-label">@Html.LabelFor(t => t.Title)</td>
<td class="display-field">@Html.DisplayFor(t => t.Title)</td>
</tr>
</table>
$('#OnDemandData').change(function () {
if ($(this).val() == 1) {
//Select all the HTML elements where ondemand-field CSS class not applied
}
else {
//TODO
}
});
아이디어는 모든 요소가 선택되면 "readonly"속성이있는 ondemand-field CSS 클래스를 추가하여 레이블 색상을 변경할 수 있다는 것입니다.
-앨런-
.not()
선택기를 사용 하여 일치하는 요소 집합에서 특정 클래스를 제외합니다.
var notOnDemand = $('.element').not('.ondemand-field');
notOnDemand.css({ 'color':'red' });
.element {
width:100%;
float:left;
border:1px solid #d8d8d8;
margin:2px 0;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<h1>Apply red color to all exept '.ondemand-field'</h1>
<div class='element'>Element</div>
<div class='element ondemand-field'>Element (ondemand-field)</div>
<div class='element'>Element</div>
<div class='element ondemand-field'>Element (ondemand-field)</div>
<div class='element'>Element</div>
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다