0
我使用的是這裏找到的例子:https://stackoverflow.com/a/18110473/4847069,但我也想檢查一下div是否被切換。我對Jquery不太熟悉,所以在添加if條件時遇到問題。任何幫助將不勝感激!謝謝!如何確定Div是否被切換Jquery
我使用的是這裏找到的例子:https://stackoverflow.com/a/18110473/4847069,但我也想檢查一下div是否被切換。我對Jquery不太熟悉,所以在添加if條件時遇到問題。任何幫助將不勝感激!謝謝!如何確定Div是否被切換Jquery
使用$(obj).is(':visible')
來確定對象obj
是否已被切換爲「可見」。
使用例如在連接後:
$('.orange').hide();
$('.gray, .orange').on('click', function() {
$('.gray, .orange').toggle();
if($('.gray').is(':visible')) {
$('#output').html('gray');
}
else {
$('#output').html('orange');
}
});
.blue{
height:100px;
width:250px;
background:#1ecae3;
float:left;
}
.gray{
height:100px;
width:100px;
background:#eee;
float:left;
}
.orange{
height:100px;
width:150px;
background:#fdcb05;
float:left;
}
#output {
clear: both;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="blue"></div>
<div class="gray">
<p> Show --> </p>
</div>
<div class="orange" >
<p> -- Hide </p>
</div>
<div id="output"></div>
偉大的作品!謝謝! –