代码如下:
<!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>
求解答,为什么会消失,怎么才能不消失?
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对象
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。