【问题标题】:HTML javascript checkbox functionHTML javascript 复选框功能
【发布时间】:2023-03-07 22:43:01
【问题描述】:

我有一个场景,当我选中可用账单复选框时,应该会弹出一个图像上传相机功能。我可以稍后为“图像上传”编写附带的函数。但是当我检查“可用账单”时,我需要显示“图片上传”

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>

【问题讨论】:

  • 欢迎来到 SO。请访问help center 了解如何在此处询问以及询问什么。提示:显示代码。其他提示:&lt;input type="checkbox" onclick="document.getElementById('upload').style.display=this.checked?'block':'none'" /&gt;
  • 好吧 :) 开始尝试或展示您的尝试。
  • 账单可用
  • 函数 calc() { var update=true; console.log("更新是" + update);}
  • 在问题中添加代码,而不是在 cmets 中。编辑按钮位于标签下方。并且一定要使用代码块工具({}icon)

标签: javascript html checkbox android-camera


【解决方案1】:

像这样:

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>

【讨论】:

  • 感谢您的帮助。它工作:) 我只需要应用带有图像图标的格式样式并将相机功能附加到它。您是否建议我使用差异方式来实现这一点?
  • 这是我修改的代码:{
    图片上传
    }
  • 我不会使用内联 JavaScript,也可能不会使用表格。事件处理程序中也不需要javascript: 伪标签
  • 对于您帮助我完成的同一段代码,我如何包含取消选中 on-change 选项?
  • 什么意思?我的代码在未选中时隐藏并在选中时显示
  • 猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-11
    • 2011-09-09
    相关资源
    最近更新 更多