내 else 문에 문제가 있습니다. 실행되지 않는 것 같습니다. 원하는 항목은 "dissapear"버튼을 클릭하면 "Boe "dissapears,하지만 다시 클릭하면 다시 나타납니다. 하지만 내 else 문은 "변경"버튼을 사용하여 동일하게 작동하는 것처럼 보입니다. "변경"을 클릭하면 텍스트 형식 자체가 나타나지만 다시 한 번 클릭하면 정상으로 돌아갑니다. 어떤 도움이 필요합니까? 고맙습니다!jQuery else 문이 작동하지 않습니다.
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("table").css("border","solid black 4px");
$("#dissapear").click(function(){
if ($(".boe:visible")) {
$(".boe").hide(1000);
} else {
($(".boe:visible"))
}
});
$("#change").click(function(){
if ($(".hoera").css("color","black")) {
$(".hoera").css({"color":"green","font-size":"40px","text-decoration":"underline"});
$(".boe").css({"color":"green","font-size":"40px","text-decoration":"underline"});
} else {
$(".hoera").css({"color":"black","text-decoration":"none","font-size":"19px"});
$(".boe").css({"color":"black","text-decoration":"none","font-size":"19px"});
}
});
});
</script>
</head>
<div id="tabel">
<table>
<td> <button id="dissapear">Dissapear!</button> </td>
<td> <button id="change">Change!</button> </td>
<tr><td> <p class="boe">BOE!</p> </td> </tr>
<tr><td> <p class="hoera">Hoera!</p> </td> </tr>
<tr><td> <p class="boe">BOE!</p> </td> </tr>
<tr><td> <p class="hoera">Hoera!</p> </td> </tr>
<tr><td> <p class="boe">BOE!</p> </td></tr>
<tr><td> <p class="hoera">Hoera!</p> </td></tr>
<tr><td> <p class="boe">BOE!</p> </td> </tr>
<tr><td> <p class="hoera">Hoera!</p></td> </tr>
<tr><td> <p class="boe">BOE!</p> </td> </tr>
</tr>
</table>
</div>
</body>
</html>
도움이되기를 바랍니다. '($ (". boe : visible"))'는 아무것도 유용하지 않습니다. – trincot
당신이 실제로 부르는 기능이 무엇인지 더 자세히 읽어야한다고 생각합니다. 또 다른 의심스러운 줄 :'if ($ (". hoera") .css ("color", "black"))'는 색상을 검정색으로 변경하고 jQuery 객체를 반환하며 항상 true입니다. http://api.jquery.com/ –