简体   繁体   English

HTML javascript复选框功能

[英]HTML javascript checkbox function

I have a scenario where, when I check Bills Available checkbox, a Image Upload camera function should pop-up.我有一个场景,当我选中 Bills Available 复选框时,应弹出图像上传相机功能。 I can write the came function for "Image Upload" later.我可以稍后为“图像上传”编写来的函数。 But i need "Image Upload" displayed when I check "Bills Available"但是当我检查“可用账单”时,我需要显示“图片上传”

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>

Like this:像这样:

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>

Using your code after cleaning it up:清理后使用您的代码:

 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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM