首页 > 解决方案 > 根据检查状态为 HTML 复选框输入中的名称分配不同的值

问题描述

作为表单提交的一部分,我有一个如下的输入标记。

<input type=“checkbox” id=“allowcheatmode” name=allowCheatMode value=“NO” onchange=“allowCheatModes()”&gt;

以及 JS 函数中的 allowCheatModes

function allowCheatModes(){
   var x = document.getElementById(“allowcheatmode”).checked
   if (x) {
      document.getElementById(“allowcheatmode”).value = “YES”
   } else {
      document.getElementById(“allowcheatmode”).value = “NO”
   }

但是,当我allowcheatmode在表单提交后尝试打印变量时,这不起作用。我在这里做错了什么?

标签: javascripthtml

解决方案



推荐阅读