单击时使用html、css和javascript弹出每个复选框



我需要关于如何在每个"是"one_answers"否"复选框中弹出的帮助。。我需要这些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>

上面的每个复选框都需要有一个弹出的

我搜索了一个自定义警报来自定义警报框,下面是代码。。

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<style>
#dialogoverlay{
display: none;
opacity: .8;
position: fixed;
top: 0px;
left: 0px;
background: #FFF;
width: 100%;
z-index: 10;
}
#dialogbox{
display: none;
position: fixed;
background: #000;
border-radius:7px; 
width:550px;
z-index: 10;
}
#dialogbox > div{ background:#FFF; margin:8px; }
#dialogbox > div > #dialogboxhead{ background: #666; font-size:19px; padding:10px; color:#CCC; }
#dialogbox > div > #dialogboxbody{ background:#333; padding:20px; color:#FFF; }
#dialogbox > div > #dialogboxfoot{ background: #666; padding:10px; text-align:right; }
</style>
<script>
function CustomAlert(){
this.render = function(dialog){
var winW = window.innerWidth;
var winH = window.innerHeight;
var dialogoverlay = document.getElementById('dialogoverlay');
var dialogbox = document.getElementById('dialogbox');
dialogoverlay.style.display = "block";
dialogoverlay.style.height = winH+"px";
dialogbox.style.left = (winW/2) - (550 * .5)+"px";
dialogbox.style.top = "100px";
dialogbox.style.display = "block";
document.getElementById('dialogboxhead').innerHTML = "Definition";
document.getElementById('dialogboxbody').innerHTML = dialog;
document.getElementById('dialogboxfoot').innerHTML = '<button onclick="Alert.ok()">OK</button>';
}
this.ok = function(){
document.getElementById('dialogbox').style.display = "none";
document.getElementById('dialogoverlay').style.display = "none";
}
}
var Alert = new CustomAlert();
</script>
</head>
<body>
<div id="dialogoverlay"></div>
<div id="dialogbox">
<div>
<div id="dialogboxhead"></div>
<div id="dialogboxbody"></div>
<div id="dialogboxfoot"></div>
</div>
</div>
<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" onclick="Alert.render('Good Choice!')">
<label for="yes">Yes</label>  
<input type="checkbox" id="no" name="boolean" value="No" onclick="Alert.render('Too bad :c')">
<label for="no">No</label>
</div>
</body>
</html>

这个现在看起来很不错,所以谢谢你们帮我学习

<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>

最新更新