我使用 jQuery 构建了一个展开/折叠插件。当我将它与一个一起使用时它工作正常div
。但是当我尝试将它与另一个div
. 我在这里做错了什么?
这是我将插件应用到的 HTML 代码:
<div class="col">
<div class="tabs ui-tabs ui-widget ui-widget-content ui-corner-all" id="box-resize">
<div id="ui-tabs-1" class="ui-tabs-panel ui-widget-content ui-corner-bottom" aria-live="polite" aria-labelledby="ui-id-13" role="tabpanel" aria-expanded="true" aria-hidden="false">
<div class="item">
<ul class="item_list">
<li>Singapore</li>
<li>Singapore</li>
<li class="last_item_list">12 hours ago</li>
</ul>
</div>
</div>
<div id="ui-tabs-2" class="ui-tabs-panel ui-widget-content ui-corner-bottom" aria-live="polite" aria-labelledby="ui-id-14" role="tabpanel" style="display: none;" aria-expanded="false" aria-hidden="true"></div>
</div>
<div class="green_end mapexpand">
<div class="column">
<div class="mapexpand" id="mapresize">
<span>Expand</span>
</div>
</div>
</div>
</div>
<div class="col">
<div class="tabs ui-tabs ui-widget ui-widget-content ui-corner-all" id="box-resize">
<div id="ui-tabs-1" class="ui-tabs-panel ui-widget-content ui-corner-bottom" aria-live="polite" aria-labelledby="ui-id-13" role="tabpanel" aria-expanded="true" aria-hidden="false">
<div class="item">
<ul class="item_list">
<li>Singapore</li>
<li>Singapore</li>
<li class="last_item_list">12 hours ago</li>
</ul>
<a href="#"><img class="edit" src="images/icons/pencil.png"></a>
</div>
</div>
<div id="ui-tabs-2" class="ui-tabs-panel ui-widget-content ui-corner-bottom" aria-live="polite" aria-labelledby="ui-id-14" role="tabpanel" style="display: none;" aria-expanded="false" aria-hidden="true"></div>
</div>
<div class="green_end mapexpand">
<div class="column">
<div class="mapexpand" id="mapresize">
<span>Expand</span>
</div>
</div>
</div>
</div>
这是实际的插件:
var mr=$('#mapresize');
mr.click(function() {
if ($(this).is('.mapexpand')) {
$(this).removeClass('mapexpand').addClass('mapcollapse');
$("#box-resize").animate({
height: '100%'
}, 500, function() {
mr.find('span').text('collapse');
});
} else {
$(this).removeClass('mapcollapse').addClass('mapexpand');
$("#box-resize").animate({
height: '150px'
}, 500, function() {
mr.find('span').text('expand');
});
}
return false;
});