如果取消选中,则如何使此代码隐藏属性桥,如果再次检查,则将其还原回来?
var bridge = new ol.layer.Tile({
title: 'Bridge',
opacity: opacity,
//visible: false,
source: new ol.source.TileWMS({
url: geoserverUrlPath + '/geoserver/wms',
params:{
'LAYERS':'pasco_benim:bridge',
'TILED': true
},
serverType: 'geoserver'
}),
layerName: 'bridge'
});
bridge.on('change:visible', function(){
//alert("alert");
$('#bridge').hide();
});
答案 0 :(得分:0)
如果bridge
是type=checkbox
输入,则可以尝试
$('#bridge').toggle();
或者如果您想更具体地使用this.checked
或!this.checked
来反转逻辑:
bridge.on('change', function() {
$('#bridge').toggle( this.checked );
});
由于您没有提供任何最小,完整和可验证的示例,这是我的:
const bridge = $("#bridge-input"),
bridgeDiv = $("#bridge");
bridge.on('change', ()=> bridgeDiv.toggle( this.checked ) );
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type=checkbox id=bridge-input>
<div id=bridge>BUNGALUNGA</div>