我有一個來自 PHP/Mysql 代碼的多開關切換,我想在當前處于ON 的切換中顯示div。
另外,我想在打開/關閉切換開關時顯示/隱藏 div

我的 PHP 代碼:
<li>
<?php echo $_ship_method_value['shipping_title'];?>
<label class="switch">
<!-- Toggled Case -->
<input type="checkbox" id="toggd" name="toggle" value="<? echo $_ship_method_value['shipping_id']; ?>" class='cmn-toggle cmn-toggle-round' data-switchery <? if(array_key_exists("shipping_available",$_ship_method_value)) echo 'checked'; ?> />
<span class="slider round hide-off"></span>
</li>
<div class="show-hide">
<p>Want to show this div ;-)</p>
</div>
我的 jQuery 代碼
$('input[name=toggle]').change(function(){
var mode = $(this).prop('checked');
if(mode == true){
$(".show-hide").show();
}else{
$(".show-hide").hide();
}
});'
但此代碼僅適用于單擊單個切換事件的切換。
請幫我找到解決方案。謝謝!
uj5u.com熱心網友回復:
$('.toggle_check_box').change(function(){
var mode = $(this).prop('checked');
if(mode == true){
$(".show-hide").show();
}else{
$(".show-hide").hide();
}
});
你可以為你的復選框應用類并像這樣使用..這將在所有開關按鈕上切換div
uj5u.com熱心網友回復:
$('body').on('change', 'input[name=toggle]', function() {
var mode = $(this).prop('checked');
if (mode == true) {
$(".show-hide").show();
} else {
$(".show-hide").hide();
}
});
** 更新 **
如果 div 位于 li 旁邊,那么下面的代碼將適用于您。
$('body').on('change', 'input[name=toggle]', function() {
var mode = $(this).prop('checked');
if (mode == true) {
$(this).closest("li").next(".show-hide").show();
} else {
$(this).closest("li").next(".show-hide").hide();
}
});
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/339762.html
標籤:javascript php 查询 mysql
上一篇:將資訊從AJAX傳遞到控制器類
