FIXED
通过将 mplungjan 的代码编辑为以下内容来修复它:
$(function() {
$("#foo").on("click",function() {
if ($(this).is(':checked')) $('#checked-a').show('fast',function() {
$('#checked-b').css("width","60%");
$('#checked-a').css("width","40%");
}) ;
else $('#checked-a').show('fast',function(){
$('#checked-b').css("width","100%").show();
$('#checked-a').css("width","0%").hide();
});
});
});
我希望当隐藏右侧 div (40%) 时,左侧 div 为 100%(当前 60%)。
screenshot with checked checkbox:
![with checkbox checked (default)](https://i.stack.imgur.com/Cd062.png)
screenshot with unchecked checkbox:
![unchecked (div is hidden)](https://i.stack.imgur.com/odQWG.png)
现在我想让左边的 div 覆盖页面的整个宽度(100%)。
这是我的代码:
javascript:
<script type="text/javascript">
$(function(){
($('input[name = "foo"]').is(':checked'))
$('#checked-a').slideDown('fast');
});
</script>
div:
<div class="content2" id="checked-a">
<%= yield %>
</div>
html 输入:
<input type="checkbox" checked="checked" name="foo" value="1" onclick="$(this).is(':checked') && $('#checked-a').slideDown('fast') || $('#checked-a').slideUp('fast');"/>
希望有人能帮忙:)