jquery - 在 jQuery 中使用 prependTo() 时出现问题

标签 jquery prepend

我在尝试使用 jQuery 中的 prependTo() 函数时遇到问题...由于某种原因我无法让它工作

$("
<div id="note178" class="note"> 
 <div class="delete"><a href="/chart-notes/delete/178" onclick="$.ajax({ dataType: 'script', url: '/chart-notes/delete/178'}); return false;"><img src='/images/icons/delete.png'></a></div> 
 <div class="timestamp">1 minute ago </div> 
 <div class="content">ñasdas dasdasdasd conclusión</div>  
</div>
").prependTo(".notes").fadeIn("slow");

尽管这样做时,效果很好

$.ajax({
  url:'/chart-notes/show/<cfoutput>#chartnote.id#</cfoutput>',
  success: function(data) {
   $(data).prependTo(".notes").fadeIn("slow");

   // Scroll to the top of the annotations
   $('html, body').animate({scrollTop: $(".notes").offset().top}, 1000);

   // Clear the form
   $('#chartnote-notes').val("");  
  }
 });

来自该成功函数的“数据”响应是相同的

<div id="note178" class="note"> 
 <div class="delete"><a href="/chart-notes/delete/178" onclick="$.ajax({ dataType: 'script', url: '/chart-notes/delete/178'}); return false;"><img src='/images/icons/delete.png'></a></div> 
 <div class="timestamp">1 minute ago </div> 
 <div class="content">ñasdas dasdasdasd conclusión</div>  
</div>

和以前一样

最佳答案

另外,IIRC,在调用fadeIn之前,你必须为#note178设置“display: none”,否则你将看不到任何淡入淡出效果。

关于jquery - 在 jQuery 中使用 prependTo() 时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2445408/

相关文章:

javascript - 使用轮播滑动图像

jquery - 如何使用 jQuery 修改 json 数组

javascript - 在元素外部单击时如何切换类 Jquery

javascript - 如何使用 jquery 在一般 DOM 对象调整大小上触发事件

javascript - jQuery document.ready 不前置

javascript - jQuery .prepend 一个变量

javascript - 使用node.js时包含外部js

jQuery prepend - 防止自动滚动

vector - 在 Clojure 中添加向量的惯用方法是什么?

javascript - 如何删除前置的同级项目