我正在使用一个具有一些自定义要求的devExpress表。
(更新)休息了一天,然后回来,使用React样式正确地完成了它!感谢您的建议

在截图中,我禁用了某些单元格。但是,用户希望所有单元格都显示为禁用状态,而不是选中的行。
使用这个
window
.$("td")
.not(document.getElementById(this.state.selection[0]))
.not(document.getElementsByClassName(this.state.selection[0]))
.not("td:first-child")
.not(window.$("td:contains('iPlay')"))
.not(window.$("td:contains('iLOE')"))
.not(window.$("td:contains('iInvest')"))
.not(window.$("td:contains('SPACER')"))
.not(window.$("td:contains('$MM')"))
.not(window.$("td:contains('$/BOE')"))
.attr("style", "color:#868a8f");
window
.$("td > div > div > div > input")
.not(document.getElementsByClassName(this.state.selection[0]))
.attr("style", "color:#868a8f");我设法在页面加载上达到了预期的结果

我的问题是,当我选择一个新行时,我不能删除我之前应用的颜色,因为它没有被选中。我尝试使用"has“来查找选定的行,并将颜色改回继承或完全删除样式属性。
window
.$("td")
.has(document.getElementById(this.state.selection[0]))
.has(document.getElementsByClassName(this.state.selection[0]))
.not("td:first-child")
.not(window.$("td:contains('iPlay')"))
.not(window.$("td:contains('iLOE')"))
.not(window.$("td:contains('iInvest')"))
.not(window.$("td:contains('SPACER')"))
.not(window.$("td:contains('$MM')"))
.not(window.$("td:contains('$/BOE')"))
.attr("style", "color:inherit");
window
.$("td > div > div > div > input")
.has(document.getElementsByClassName(this.state.selection[0]))
.attr("style", "color:inherit");如果有帮助,我确实有未被选中的行的I。我试着用它做点什么,但没有任何运气
const otherRows = ExpensesUtils.ROW_PROPS.filter(x => x !== this.state.selection[0]);
for (let i = 0; i < otherRows.length; i += 1) {
window
.$("td")
.has(document.getElementById(otherRows[i]))
.has(document.getElementsByClassName(otherRows[i]))
.attr("style", "color:inherit");
window
.$("td > div > div > div > input")
.has(document.getElementById(otherRows[i]))
.has(document.getElementsByClassName(otherRows[i]))
.attr("style", "color:inherit");
}链接到超文本标记语言Table HTML
this.state.selection是从以下列表中选择的rowId
我已经将rowIds应用于嵌套组件中的类。我想不出另一种访问它们的方法。
const ROW_PROPS = [
"leaseAndWellExpense",
"leaseAndWellExpenseBoe",
"iloeLeaseAndWellExpense",
"iloeLeaseAndWellExpenseBoe",
"gnaLeaseAndWell",
"gnaLeaseAndWellBoe",
"transportation",
"transportationBoe",
"divisionGnA",
"divisionGnABoe",
"gatheringProcessing",
"gatheringProcessingBoe",
"hqGnA",
"hqGnABoe",
"interestExpense",
"interestExpenseBoe",
"netProdBoe",
"leaseImpairments",
"leaseImpairmentsBoe",
"ddaProducing",
"ddaProducingBoe",
"iInvestDdaProducing",
"iInvestDdaProducingBoe",
"ddaGatheringProcessing",
"ddaGatheringProcessingBoe",
"iInvestDdaGatheringProcessing",
"iInvestDdaGatheringProcessingBoe",
"marketingCosts",
"otherIncomeExpense",
"otherIncomeExpenseBoe",
"otherRevenue",
"incomeTaxProvision",
"incomeTaxProvisionBoe",
"severanceTaxes",
"severanceTaxesPercent",
"currentTaxes",
"currentTaxesRate",
"netWellHeadRevenue",
];发布于 2021-02-01 15:26:11
最简单的方法是创建CSS规则的样式表。
在样式表中,您应该定义2类。
让我们假设1用于您想要的CSS规则,另一个用于默认/无规则。
我只是向你展示了做这件事的最简单的版本,但有另一个方面。
$('#b1').on('click', function() {
$('.c1').removeClass('c1');
$(this).addClass('c2');
});.c1 {
color: red;
}
.c2 {
color: green;
}<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button id="b1">Change</button>
<p class="c1">This is a Test Line.</p>
发布于 2021-02-02 10:32:41
最简单的方法是
$('#idName').on('click', function()
{
$('.className').removeClass('removeClassName');
$(this).addClass('addClassName');
});上面的代码意味着当单击id为IdName的按钮时,带有className的元素将移除removeClassName的类,并添加addClassName的类。
要获得进一步的说明,可以查看Removing CSS Using JQuery Documentation
发布于 2021-02-03 20:43:45
你可以通过另一种方式来实现它。而不是玩弄样式属性,因为它需要最高的特异性,所以它可能会在某个地方产生问题。相反,您可以使用toggleClass。首先,将默认样式添加到表中,无论何时单击任何行,都可以使用切换类Toggle Class Example
举例说明。
$("td > div > div > div").click(function(){
$("input").toggleClass("main");})
https://stackoverflow.com/questions/65776147
复制相似问题