-1

在我的网站上,当我单击隐藏的服装区域按钮时,一切都关闭了。

当我单击此按钮时,我不想关闭它们。但他们是封闭的。

我该怎么做。

<!DOCTYPE html>
<html>
<head>
  <style>
  p { background:red; }
</style>
  <script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
  <p>

It is a long established fact that a reader will be distracted. The point of using Lorem Content is here...

  </p>
  <p>
  <span>Mr [Name], [Surname]</span>
  <a href="http://www.mobilyala.com" />
       <img src="http://www.mobilyala.com/home.png" alt="Home" />
   </a>
   Welcome to our website. You can read all about our services. We are working on dekorasyon

   <button>Hidden Custom Area</button>

</p>
<script>
  $("button").click(function () {
    $("p").empty();
  });
</script>

</body>
</html>
4

1 回答 1

5

该代码删除了每个<p>元素的内容。你还期待什么?

如果您只想要<p>包含按钮,请使用 thios:

$(this).closest('p').empty();

而不是.empty()你可能还想要.remove().

于 2012-05-18T11:07:19.497 回答