各セルにチェックボックスがあり、ユーザーがそのセルにマウスを合わせるまで非表示になっているテーブル(以下を参照)があります。チェックボックスがチェックされている場合、マウスがセルを離れても表示されたままになります。チェックされていない場合、チェックボックスは再び非表示になります。
私が抱えている問題は、ユーザーが現在ホバーしている個々のセルのチェックボックスを表示する方法がわからないことです。その瞬間、任意のセルにマウスを合わせると、次のようにすべてのチェックボックスが表示されます。
セルが設定されている場所に関する私の見解:
@for (int i = 0; i < Model.Users.Count(); i++) {
<tr>
@for (int j = 0; j < Model.Users.Count(); j++) {
string background = Model.AssignedArray[i] == j ? "background-color:#157fa0" : null;
string text = Model.AssignedArray[i] == j ? "color:#ffffff" : null;
<td class="tableCell" style="text-align: center; @background; @text">
@Model.Matrix[i, j]
<input type="checkbox" class="hideCheckBox" name="forcedAssigned" value="">
</td>
}
</tr>
チェックボックスのJavaScript:
<script>
$('.tableCell')
.mouseenter(function () {
$(".hideCheckBox").show();
})
.mouseleave(function () {
if ($(".hideCheckBox").is(":checked"))
$(".hideCheckBox").show();
else
$(".hideCheckBox").hide();
});
</script>
CSS:
.hideCheckBox {
display: none;
}
スクリプトが間違っていますが、個々のセルを操作するように修正する方法がわかりません。
javascriptをまったく使用せずに、これを簡単に実現できます。ただ、デフォルト設定display
のinput type="checkbox"
にはnone
、いつtd
れる:hover
編、またはinput type="checkbox"
され:checked
、上書きするdisplay
ので、同様に、プロパティを:
td {
border: solid 1px red;
margin: 5px;
width: 40px;
height: 40px;
}
td input { display: none; }
td:hover input { display: inline; }
td input:checked {display: inline; }
<table>
<tr>
<td><input type ="checkbox" /></td>
<td><input type ="checkbox" /></td>
<td><input type ="checkbox" /></td>
<td><input type ="checkbox" /></td>
</tr>
<tr>
<td><input type ="checkbox" /></td>
<td><input type ="checkbox" /></td>
<td><input type ="checkbox" /></td>
<td><input type ="checkbox" /></td>
</tr>
<tr>
<td><input type ="checkbox" /></td>
<td><input type ="checkbox" /></td>
<td><input type ="checkbox" /></td>
<td><input type ="checkbox" /></td>
</tr>
<tr>
<td><input type ="checkbox" /></td>
<td><input type ="checkbox" /></td>
<td><input type ="checkbox" /></td>
<td><input type ="checkbox" /></td>
</tr>
</table>
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加