ReplaceWith 隐藏元素然后显示在原始位置,而不是目标位置
链接:http://jsfiddle.net/7GGeX/24/
点击1,2中的链接,3 命令你就会明白我为什么感到困惑了。
在replaceWith中使用函数是否会否定替换的定位?
$(document).ready(function () {
$(".click1").click(function () {
$("#one").replaceWith(function () {
$('#replace1').show();
});
return false;
});
感谢您的帮助!
Link: http://jsfiddle.net/7GGeX/24/
Click on the links in 1,2,3 order and you'll see why I'm confused.
Does using a function inside replaceWith negate the positioning of the replacement?
$(document).ready(function () {
$(".click1").click(function () {
$("#one").replaceWith(function () {
$('#replace1').show();
});
return false;
});
Thanks for the help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要
返回
要用作替换的值。或者不传递函数:
由于您没有显式返回任何内容,因此会显示
replace
div,然后返回undefined
,从而有效地用任何内容替换原始内容。You need to
return
the value you want to use as the replacement.or don't pass a function:
Since you weren't returning anything explicitly, the
replace
div was being shown, thenundefined
was returned, effectively replacing the original with nothing.