append()不在safari中工作但在IE6中工作

时间:2010-08-04 09:03:33

标签: javascript jquery

由于某种原因我无法让append()在safari中工作,但它在IE6中工作正常!!我遇到的问题是$( "#newsList .newsItemHeading" ).each(function(){})和  $( "#newsList .newsListItem" ).each(function(){})无效。我尝试在一个警告框中显示Safari中的<ul id="newsList">内容,它返回空白。

它只是因为我无法访问jquery中使用apend()添加的元素,但元素正在完美地选择CSS样式。我在这里缺少一些东西?或者我应该使用其他技术吗?

HTML:

<html>
 <div class="news-container">
  <ul id="newsList">
  </ul>
 </div>
</html>

jQuery的:

$.ajax({
   url:      'news.htm',
   type:     'GET',
   dataType: 'html',
   success:  function(data){
    var $content = $(data).find('.newsItemContent');
       $content.each(function(){
         var li = $("<li>"+"<div class=newsItemHeading>"+$(this).children("h1").text()+"</div>"+"<div class=newsListItem>"+$(this).clone().children("h1").remove().end().text()+"</div>"+"</li>");
         $("#newsList").append(li);

       });
    }
});


$( "#newsList .newsItemHeading" ).each(function(){
  $(this).bind('click', function() {
    window.location.href='news.htm';
  });    
});

$( "#newsList .newsListItem" ).each(function(){
  $(this).html($(this).html().substring(0,135)+'<a href="news.htm">...</a>');
});

如果问题不明确,请告诉我。如果需要,我会提供更多详细信息,以便更容易理解问题所在

1 个答案:

答案 0 :(得分:0)

我想说,最后两个函数在最后工作,但是添加列表项的ajax请求“太慢”,并且在列表元素之前将评估函数。所以选择器匹配0个元素。

试图让$( "#newsList .newsItemHeading" ).length知道有多少元素?

相关问题