javascript - 根据检查状态为 HTML 复选框输入中的名称分配不同的值
问题描述
作为表单提交的一部分,我有一个如下的输入标记。
<input type=“checkbox” id=“allowcheatmode” name=allowCheatMode value=“NO” onchange=“allowCheatModes()”>
以及 JS 函数中的 allowCheatModes
function allowCheatModes(){
var x = document.getElementById(“allowcheatmode”).checked
if (x) {
document.getElementById(“allowcheatmode”).value = “YES”
} else {
document.getElementById(“allowcheatmode”).value = “NO”
}
但是,当我allowcheatmode
在表单提交后尝试打印变量时,这不起作用。我在这里做错了什么?
解决方案
推荐阅读
- swift - 每次查看 LoginViewController
- mysql - MySQL按位比较
- amazon-web-services - 如何指定空的 snapshot_identifier 或数据源值
- windows - Select-String 不显示与 Get-AppxPackage 的所有匹配项
- java - Spring MVC 设置中的配置问题
- ios - 下次启动应用程序时,如何检查数据是否成功存储在 coredata 中?- iOS 斯威夫特
- c++ - 如果在子类中没有构造方法,则错误“没有用于调用 'LGame::LGame(String&)' 的匹配函数”
- xamarin - 为 Xamarin 注册 Intune 后未调用 RestartApplication
- python - 如何使用while循环终止python脚本并获得结果?
- apache-spark - Spark Standalone vs YARN