我对 JavaScript/jQuery 有疑问。我试图在显示对话框后更改变量的值,并且如果检查了复选框,但是当我检查它的值时这不起作用。我能做些什么或者这个代码是错误的?
HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>JS/jQuery</title>
<link rel="stylesheet" type="text/css" href="style.css">
<script type="text/javascript" src="jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="myjs.js"></script>
</head>
<body>
<div class="back"></div>
<div class="start">
<label for="chex">Is this checkbox checked?</label>
<input type="checkbox" id="checkexist" name="chex" />
<button id="run">Run form</button>
</div>
<div class="window"></div>
</body>
</html>
JavaScript:
$(document).ready(function() {
var start = false;
var check = false;
if (start == false) {
$("#checkexist").click(function(){
if (this.checked) {
check = true;
}
});
$("#run").click(function(){
start = true;
$(".start").fadeOut('slow', function(){
$(".start").css("display", "none");
});
$(".back").fadeOut('slow', function(){
$(".back").css({'display' : 'none', 'opacity' : '0', 'filter' : 'alpha(opacity=0)'});
});
});
} else {
if (check == true) {
$(".window").click(function(){
$(".window").hide('fast');
});
} else {
//do something
}
}
});