-1

我创建了一个列表页面,其中每个列表都有自己的 div,该 div 的内容是通过 $.post 从单独的 php 脚本加载的

我遇到的问题是试图隐藏列表,我认为问题可能与这条线有关

$('div.close_listing')

只有我使用它才能让它工作

$('div.close_listing) (当我单击列表 div 中的任意位置时有效)

非常感谢任何帮助。

清单的 html 代码是:

<div id='listing'>
   <div id='loading'></div>
   <a name='13'><h3>Business1</h3></a> <h4 data-id=18-3-3>Name Of Business 1</h4>
    <div>
        <hr>
     *** content forbusiness1 appears here ***
          <div class='close_listing'>CLOSE this listing</div>
    </div>

   <a name='14'><h3>Business2</h3></a> <h4 data-id=19-3-3>Name Of Business 2</h4>
    <div>
        <hr>
     *** content for business2 appears here ***
          <div class='close_listing'>CLOSE this listing</div>
    </div>

</div>

调用内容的代码如下:

$(document).ready(function() { 
$('div.listing> div').hide();  
$('div.listing> h4').click(function() {
$('div.listing> div').empty().html('<img src="loading_image.gif" /><br>Retrieving Details.....');
$.post("http://www.example.com/record.php", { id: $(this).attr('data-id') });

$.post('show.php',{ id: $(this).attr('data-id')}, function(data) {
$('div.listing> div').html(data); 

$('div.listing .close').visible();
});

var $nextDiv = $(this).next();
var $visibleSiblings = $nextDiv.siblings('div:visible');

if ($visibleSiblings.length ) {
  $visibleSiblings.slideUp('fast', function() {
    $nextDiv.slideToggle('fast');
  });
} else {
   $nextDiv.slideToggle('fast');
} 
});

// closes the listing down

$('div.close_listing').click(  
function() {
$('div.listing> div').hide(); 
}); 

});
4

1 回答 1

0

我认为你应该这样做:

<a href="javascript:$(this).parent().hide();">CLOSE this listing</a>

如果我没有误解你的目的。:D

于 2012-05-29T16:17:56.997 回答