HTML javascript复选框功能

HTML javascript checkbox function

本文关键字:功能 复选框 javascript HTML      更新时间:2023-09-26

我有一个场景,当我选中"可用票据"复选框时,应该弹出"图像上传"相机功能。我可以稍后为"图像上传"编写附带功能。但当我检查"可用票据"时,我需要显示"图像上传"

function calc()
{
var update=false;
console.log("update is" + update);
}
<td><input class="pop" id="exp" type="checkbox"  name="bill available" value="" onchange="calc();"/>Bill available<br></td>

像这样:

window.onload = function() {
   document.getElementById("exp").onclick = function() {
     document.getElementById('upload').className = this.checked ? '' : 'hide';
   }
}

window.onload = function() {
   document.getElementById("exp").onclick = function() {
     document.getElementById('upload').className = this.checked ? '' : 'hide';
   }
}
.hide {
  display: none
}
<input class="pop" id="exp" type="checkbox" name="bill_available" value="" /><label for="exp">Bill available</label>
<div class="hide" id="upload">Upload</div>

清理后使用您的代码:

    window.onload = function() {
      document.getElementById("exp").onclick = function() {
        document.getElementById('upload').className = this.checked ? '' : 'hide';
      }
    }
    .hide {
      display: none
    }
<table>
  <tr>
    <td>
      <input class="pop" id="exp" type="checkbox" name="bill_available" value="" />
      <label for="exp">Bill available</label>
    </td>
    <td class="hide" id="upload">
      <img id="p2" src="./images/camera 40.PNG" style="width:30px;height:30px;" 
      onclick="window.location='4s.html'" /><b>Image Upload</b>
    </td>
  </tr>
</table>