单击项目时在 javascript 中删除一个单词

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15891011/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 02:28:30  来源:igfitidea点击:

Strike out a word in javascript when item clicked

javascriptjqueryhtmlcss

提问by Beslinda N.

Strike out a word in javascript/jquery when item clicked.

单击项目时,在 javascript/jquery 中删除一个单词。

So I am clicking and item ,the item fades out but in the same time I want the text to strike out.

所以我点击和项目,项目淡出但同时我希望文本删除。

Ex. I have an apple(image) and a apple(text). When I click on the apple I want the image to fade out and the text to strike out.

前任。我有一个苹果(图片)和一个苹果(文字)。当我点击苹果时,我希望图像淡出并且文本被删除。

<div id="items">
  <p>Apple</p>
</div>
<div id="content">
  <div class="box" id="pic1"> <img src = /images/apple.png  /></div>
    <script>
      $("#pic1").click(function () {
        $("#pic1").fadeOut("slow");
       });
    </script>

This is my code until the image fades out but I cannot figure out how can I make the text to strike out???

这是我的代码,直到图像淡出,但我不知道如何使文本被删除???

采纳答案by Travis J

jsFiddle Demo

jsFiddle 演示

You could wrap the text in <del>

你可以将文本包裹在 <del>

$("#pic1").click(function () {
 $("#items p").wrap("<del>");
 $("#pic1").fadeOut("slow");
});

回答by tymeJV

Try putting this after the fade.

尝试在褪色后放置它。

$(this).parents("p").css("text-decoration", "line-through");