我的问题是我已经有一些'突出显示'(意味着他们有自己的背景颜色突出显示)我的表格中的单元格,当我使用代码改变整行的颜色时,它不会改变它们的背景颜色正在他们上空徘徊.
悬停在一行上只会改变未突出显示的单元格的背景颜色.
如何解决这个问题,以便整行改变背景颜色?
我有这个HTML表格:
$(window).load(function() {
$('#infotable tr').hover(function() {
$(this).addClass('hover');
}, function() {
$(this).removeClass('hover');
});
});Run Code Online (Sandbox Code Playgroud)
#infotable td {
padding:0.7em;
border:#969696 1px solid;
}
.highlight {
background:#DAFFD6;
}
.hover {
background:yellow;
}Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js"></script>
<table>
<thead>
<tr>
<th></th>
<th>Column 1</th>
<th>Column 2</th>
<th>Column 3</th>
</tr>
</thead>
<tbody id="infotable">
<tr>
<td>Row #1</td>
<td>889 kg</td>
<td class="highlight">151 kg</td>
<td>192 kg</td>
</tr>
<tr>
<td>Row #2</td>
<td>784 kg</td>
<td>15 kg</td>
<td class="highlight">64 kg</td>
</tr>
</tbody>
</table>Run Code Online (Sandbox Code Playgroud)
我有简单的选择选项 html:
<select name="individual_taxCountry" id="individual_taxCountry" class="select2">
<option value="" selected="selected" class="selected">Select a country</option>
<option value="Afghanistan" >Afghanistan</option>
<option value="Aland Islands" >Aland Islands</option>
<option value="Albania" >Albania</option>
<option value="Algeria" >Algeria</option>
<option value="Zambia" >Zambia</option>
<option value="Zimbabwe" >Zimbabwe</option>
</select>
Run Code Online (Sandbox Code Playgroud)
我为此使用 select2:
$(document).ready(function(){
$(".select2").select2();
});
Run Code Online (Sandbox Code Playgroud)
我还使用此 css 自定义了选择的外观:
.select2-container--default .select2-selection--single
{
background-color: #21262d;
border-color: #21262d;
border-top-color: #21262d;
border-right-color-value: #21262d;
border-bottom-color: #21262d;
border-left-color-value: #21262d;
height: 34px;
}
Run Code Online (Sandbox Code Playgroud)
它看起来是我想要的方式,但当用户这样做时,我想将所选项目的字体颜色更改为白色。我怎样才能做到这一点?
编辑:因为并不是每个人似乎都理解我的目标 -仅当用户从列表中选择他/她自己的项目时,我才想更改为白色(fff)。我想要的默认选项是黑暗的。换句话说:“选择一个国家/地区”应该是深色,当用户从列表中选择一个国家/地区时,我想将字体颜色更改为白色。
假设我有一个字符串:
"C:\Program Files (x86)\Steam\steam.exe /lets go 342131 some random text"
Run Code Online (Sandbox Code Playgroud)
我想从该字符串中删除'steam.exe'以及之后的所有内容.所以我的修剪过的字符串看起来像:
"C:\Program Files (x86)\Steam\"
Run Code Online (Sandbox Code Playgroud)
我怎么能在C#中做到这一点?