简体   繁体   English

使用 Jquery 或 JS 点击按钮显示和隐藏一段中的多个单词

[英]click on button to show and hide multiple words in one paragraph using Jquery or JS

I have added one button in my web app.我在我的 web 应用程序中添加了一个按钮。 which is use full for users where users click on the button to show the right word on the paragraph.对于用户单击按钮以在段落中显示正确的词的用户来说,这是完全使用的。

for example "Lorem ipsum is dummy test."例如“Lorem ipsum 是虚拟测试。” here TEST word is wrong, click on the 'Show Correct Answer' button to show the correct word after the wrong word, and again press button to hide correct word.这里的测试词是错误的,点击“显示正确答案”按钮在错误的词后显示正确的词,然后再次按下按钮隐藏正确的词。

Here is my code for hide and show text but it is useful for only one word I need to apply in multiple words in one paragraph.这是我用于隐藏和显示文本的代码,但它仅适用于我需要在一个段落中应用于多个单词的一个单词。

 function showhide() { var div = document.getElementById('newpost'); div.classList.toggle('hidden'); }
 .hidden{display: none;}.cans{background-color: red;}
 Question1: Lorem ipsum dummy text <div id="newpost" class="hidden cans">Answer1</div> Lorem Ipsum has been the industry's <div id="newpost" class="hidden cans">Answer2</div> to make a type specimen book <div id="newpost" class="hidden cans">Answer3</div>. <br><br> <button class="ans" id="button" onclick="showhide()">Show correct Answer</button>

You can use Jquery methods called.hide() or.show() to view or not your element.您可以使用 Jquery 方法调用.hide() 或.show() 来查看或不查看您的元素。 All you need to do is set an id to the element that you want to hide or show ad when the button is called you can call a function similar to this:您需要做的就是在调用按钮时为要隐藏或显示广告的元素设置一个 id 您可以调用 function 类似于此:

function hide(){
    $("#idofyourelement").hide();  
}

function show(){
    $("#idofyourelement").show();  
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM