我创造了一个tic tac toe胜利条件,所以我要检查前三个单元格是否相等,以及它们是否首先是空的。但是,即使我满足条件,第二个内部的代码如果"没有被执行。我的代码有问题吗? (r1c1表示第一行第一列),依此类推。
android {
compileSdkVersion 22
buildToolsVersion "23.0.0"
defaultConfig {
minSdkVersion 14 //lower than 14 doesn't support multidex
targetSdkVersion 22
// Enabling multidex support.
multiDexEnabled true
}
}
dependencies {
compile 'com.android.support:multidex:1.0.1'
}

if ($('#r1c1').html() !== "") {
if (($('#r1c1').html() == $('#r1c2').html()) && ($('#r1c1').html() == $('#r1c3').html())) {
$("#table").css("display", "none");
$("#victory").css("display", "You Won");
}
}

答案 0 :(得分:1)
你的陈述很好,我测试了它:https://jsfiddle.net/nyxeen/hqyr7dbv/14/ 什么行不通的是$(" #victory")。css(" display"," You Won");应该是$(" #victory")。css(" display"," block");或$(" #victory")。show();
var isx = 'x';
$("#table td").click(function(){
$(this).html(isx);
if(isx=="x")isx="o";
else isx="x";
if ($('#r1c1').html() !== "") {
if (($('#r1c1').html() == $('#r1c2').html()) && ($('#r1c1').html() == $('#r1c3').html())) {
$("#table").hide();
$("#victory").show();
}
}
});

#table tr td{width:40px;height:40px;border: 1px solid black;background:white;cursor:pointer;};

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="victory" style="display:none">
Congratulations, You Won!
</div>
<table id="table">
<tr>
<td id="r1c1" style="text-overflow"></td>
<td id="r1c2"></td>
<td id="r1c3"></td>
</tr>
<tr>
<td id="r2c1"></td>
<td id="r2c2"></td>
<td id="r2c3"></td>
</tr>
<tr>
<td id="r3c1"></td>
<td id="r3c2"></td>
<td id="r3c3"></td>
</tr>
</table>
&#13;