<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<style type="text/css">
.fly{
float:left;
background:rgb(56,62,70);
height:160px;
}
</style>
<script src="jquery.js"></script>
</head>
<body>
<div><h1>Vacation Packages</h1><p></div>
<div class="fly">
<h2>1.Hawaiian Vacation</h2>
<ul>
<li class="vacation">comments on this deal:<br />
"Amaring Deal!!"<br />
"Can't wait to take this trip!"<br />
<button type=button>GET PRICE</button></li>
</ul>
</div>
<div class="fly">
<h2>2.Hawaiian Vacation</h2>
<ul>
<li class="vacation">comments on this deal:<br />
"Amaring Deal!!"<br />
"Can't wait to take this trip!"<br />
<button type=button>GET PRICE</button></li>
</ul>
</div>
<div class="fly">
<h2>3.Hawaiian Vacation</h2>
<ul>
<li class="vacation">comments on this deal:<br />
"Amaring Deal!!"<br />
"Can't wait to take this trip!"<br />
<button type=button>GET PRICE</button></li>
</ul>
</div>
</body>
<script type="text/javascript">
$('document').ready(function(){
var price=$('<span style="font-size:14px; color:red"><strong>from 5000</strong></span>');
$('button').on('click',function(){
//$('.vacation').append(price);
// $(this).closest('.vacation').append(price);
$(this).after(price);
$(this).remove();
});
});
</script>
</html>
点击按钮后,前面的remove会消失,为什么,怎么才能不让消失
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
3条回答 默认 最新
- Go 旅城通票 2015-02-04 00:48关注
var price=$('<span style="font-size:14px; color:red"><strong>from 5000</strong></span>'); ======> var price = '<span style="font-size:14px; color:red"><strong>from 5000</strong></span>';
你用$生成后就是对象了,DOM操作会将对象移动到当前插入的位置。变为字符串就不是dom对象了,会生成新的dom对象
解决 无用评论 打赏 举报
悬赏问题
- ¥15 thinkphp6配合social login单点登录问题
- ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
- ¥15 如何在scanpy上做差异基因和通路富集?
- ¥20 关于#硬件工程#的问题,请各位专家解答!
- ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
- ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
- ¥30 截图中的mathematics程序转换成matlab
- ¥15 动力学代码报错,维度不匹配
- ¥15 Power query添加列问题
- ¥50 Kubernetes&Fission&Eleasticsearch