javascript - 如何在 jQuery 中链接 .html() 和 .fadeIn()?
问题描述
这是我的代码:
$('.container-modal-cash').html().fadeIn(1500);
它抛出:
未捕获的类型错误:$(...).html(...).fadeIn 不是函数
为什么?我该如何解决?
通常我在.html
元素内设置内容(使用),然后显示它(使用.fadeIn
)。怎么了?
解决方案
可.html()
用于设置元素的内容,或获取元素的内容。FadeIn/Out
方法适用于 Jquery 选择器元素(我的意思是$('.test')
)。
感谢Trincot,您也可以使用这些fadeIn/fadeOut()
方法,当您使用 设置元素的内容时html()
。
$('.test').html("final content").fadeOut(1500).fadeIn(1500);
请参考下面的例子来证明这一点。
console.log("getting the contents inside");
console.log($('.test').html());
console.log("setting the contents inside");
$('.test').html('changed content');
//fade works on the JQuery selector element.
$('.test').fadeOut(1500);
$('.test').fadeIn(1500);
// you can chain the fadeIn/fadeOut methods like so
$('.test').fadeOut(1500).fadeIn(1500);
// you can also chain the fadeIn/fadeOut when setting the html content like so.
$('.test').html("final content").fadeOut(1500).fadeIn(1500);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="test">content</div>
推荐阅读
- r - 如何填写按单位和时间分组的面板数据中的缺失?
- c# - 从地址下载元数据时出错
- windows - 如何在 Windows 命令行中转义特殊字符
- django - facebook-messenger-bot 错误:何时以及为什么引发此错误“(#100)参数名称_placeholder [文本]的长度必须小于或等于640”
- php - 试图在moodle中获取特定部门的特定课程日志
- r - R包在新系统上重新安装不起作用
- flutter - changenotifierprovider 是否会处理导航?
- python - Why are multiple objects created in below implementation?
- sql - ORA-01830 将日期从一个表插入另一个表
- javascript - 无法在另一个内部有条件地要求组件