我一直在努力寻找有关如何记录用户信息的信息,例如选中复选框时的用户名(应在用户不知情的情况下记录此信息)。这是我的代码:
这是 MDB 的“开关”设计的复选框
<div>
<div class="switch">
<label>
Checked and Verified
<input type="checkbox" checked>
<span class="lever"></span>
</label>
</div>
当“离开者”(复选框)设置为 true 时,我希望记录以下内容:
<input id="username" value="@User.Identity.Name" />
@Html.EditorFor(x => x.DateCreated)
但是,我找不到 @if 语句或任何有效的 javascript 代码。 请帮助我:(
最佳答案
使用 JavaScript:
<input type="checkbox" id="myCheck" onclick="myFunction()" checked>
您可以在 JS 中构建逻辑:
function myFunction() {
// Get the checkbox
var checkBox = document.getElementById("myCheck");
// If the checkbox is checked, display the output text
if (checkBox.checked == true){
//log
} else {
//do not log
}
}
如此处所述 Link
关于javascript - ASP.Net core,如何在选中复选框时记录用户信息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50989869/