0

我想让 Jquery 检测是否将某个 div id 加载到当前页面中,然后隐藏另一个 div id 元素,例如:

<div id="A1">some content here</div> //initially this div is visible
<div id="C1" style="display: none;">some content here</div> //initially this div is invisible
<div id="B1">some content here</div>

如果 Jquery 检测到 #B1 已加载到当前页面,则隐藏 #A1 并显示 #C1。

非常感谢

4

3 回答 3

1
$(function () {
    if ($('#B1').length) {
        $('#A1').hide();
        $('#C1').show();
    }
});
于 2012-09-17T06:04:49.367 回答
1
if ($("#B1").length > 0) {
  $("#A1").hide();
  $("#C1").show();
}
于 2012-09-17T06:05:01.177 回答
0

我假设您在加载文档后加载 div,所以,

$('#B1').load('ajax/test.html', function() {
  $('#A1').hide();
  $('#C1').show();

}); 

如果您不使用 jQuery,这将onreadystatechanged在 #B1 元素上实现。其他明智的做法是在准备好文件时, $(function(){
$('#A1").hide(); $("#C1").show();});

于 2012-09-17T06:05:26.587 回答