我正在用jquery创建一个小游戏,我想要向用户显示一个小盒子,如果他们赢得了游戏。
这里的条件是对话,我试着在上面调用(correctcards ==10)
,但它不起作用。
有人能告诉我为什么吗?
(我也已经尝试创建一个新的div,当正确的卡片变成10,然后在它上面调用对话,但它不能正常工作)
if (correctCards == 10) {
endTime = new Date().getTime();
time();
console.log('Spiel endet');
$('#myDialog2').dialog({
autoOpen: true,
modal: true,
resizable: false,
draggable: false,
buttons: {
'Next Level': function() {
$(this).dialog('close');
},
'Close': function() {
$(this).dialog('close');
},
}
})
}
<div id="myDialog2">You won</div>
发布于 2018-08-11 04:16:11
您需要在if
外部创建该对话框。
$('#myDialog2').dialog({
autoOpen: false,
modal: true,
resizable: false,
draggable: false,
buttons: {
'Next Level': function() {
$(this).dialog('close');
},
'Close': function() {
$(this).dialog('close');
},
}
});
var correctCards = 10;
if (correctCards == 10) {
console.log('Spiel endet');
$('#myDialog2').dialog('open');
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script
src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"
integrity="sha256-VazP97ZCwtekAsvgPBSUwPFKdrwD3unUfSGVYrahUqU="
crossorigin="anonymous"></script>
<link href="https://code.jquery.com/ui/1.12.1/themes/smoothness/jquery-ui.css" rel="stylesheet" type="text/css">
<div id="myDialog2" style>You won</div>
https://stackoverflow.com/questions/51793390
复制相似问题