javascript - 使用 html、css 和 javascript 在点击时弹出每个复选框
问题描述
我需要有关如何在“是”和“否”的每个复选框中弹出的帮助。我需要这些 html 代码在它们的每个复选框上弹出。
<div class="col-md-12 form-group" style="display: inline-flex;">
<p>1. Do You Have a Written Mission Statement?</p>
<input type="checkbox" id="yes" name="boolean" value="Yes">
<label for="yes"></label>Yes</label>
<input type="checkbox" id="no" name="boolean" value="No">
<label for="no">No</label>
</div>
<div class="col-md-12 form-group" style="display:inline-flex;">
<p>2. Do You Have a Written Vision Statement?</p>
<input type="checkbox" id="yes" name="boolean" value="Yes">
<label for="yes">Yes</label>
<input type="checkbox" id="no" name="boolean" value="No">
<label for="no">No</label>
</div>
<div class="col-md-12 form-group" style="display:inline-flex;">
<p>3. Do You Have a Logo?</p>
<input type="checkbox" id="yes" name="boolean" value="Yes">
<label for="yes">Yes</label>
<input type="checkbox" id="no" name="boolean" value="No">
<label for="no">No</label>
</div>
<div class="col-md-12 form-group" style="display:inline-flex;">
<p>4. Do You Have a strategic Position?</p>
<input type="checkbox" id="yes" name="boolean" value="Yes">
<label for="yes">Yes</label>
<input type="checkbox" id="no" name="boolean" value="No">
<label for="no">No</label>
</div>
它们上的每个复选框都需要弹出一个
解决方案
<html>
<head>
<script>
function validateCheck(check, message) {
if (check.checked) {
dialog.show();
var x = document.getElementById("content");
x.innerHTML = message
} else {
dialog.close();
}
}
</script>
<style>
#dialog {
position: fixed;
background: #fff;
border-radius: 7px;
width: 300px;
z-index: 10;
top: 0;
bottom: 0;
left: 0;
right: 0;
position: fixed
}
</style>
</head>
<body>
<div class="col-md-12 form-group" style="display: inline-flex;">
<p>1. Do You Have a Written Mission Statement?</p>
<input type="checkbox" id="yes" name="boolean" value="Yes" onchange="validateCheck(this,'Good choice')" />
<label for="yes"></label>Yes</label>
<input type="checkbox" id="no" name="boolean" value="No" onchange="validateCheck(this,'Bad choice');" />
<label for="no">No</label>
</div>
<dialog id="dialog">
<form method="dialog">
<h2>Definition</h2>
<p id="content"></p>
<menu>
<button id="confirmBtn" value="default">OK</button>
</menu>
</form>
</dialog>
</body>
</html>
尝试这个
<html>
<head>
<script>
function validateCheck(check, message) {
if (check.checked) {
alert(message)
}
}
</script>
</head>
<body>
<div class="col-md-12 form-group" style="display: inline-flex;">
<p>1. Do You Have a Written Mission Statement?</p>
<input type="checkbox" id="yes" name="boolean" value="Yes" onchange="validateCheck(this,'Good choice')" />
<label for="yes"></label>Yes</label>
<input type="checkbox" id="no" name="boolean" value="No" onchange="validateCheck(this,'Bad choice');" />
<label for="no">No</label>
</div>
</body>
</html>
推荐阅读
- r - 如何从一组选定的列中删除 na?
- django - 如何计算不同模型中外键的所有实例?
- css - Bootstrap 4:导航栏导航项目下划线
- java - 错误:工作台自动保存后台作业错误
- javascript - 如何将此 PHP 转换为 JavaScript?
- python - 带有更改的用户代理的 Scrapy Fobidden
- javascript - 如何在 Vue.js 中使用 SMTP.js - 导入外部脚本
- macos - 在 x86-64 NASM 中为外部函数传递参数
- r - 如何在等式中忽略 NA?
- jquery - 使用 Google Analytics 进行电话链接跟踪