当我单击按钮时,在同一页面 javascript 中显示更多信息

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17079890/
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 07:01:12  来源:igfitidea点击:

When I click on the button show more information in the same page javascript

javascripthtml

提问by Liliana Torres

  <a href="#"  class="button">Read More</a><br>

I have this button on the website I don't know how to program the button that when I click Read moreshow me the information of the cd that I am selling.

我在网站上有这个按钮我不知道如何对按钮进行编程,当我点击时,它会Read more显示我正在销售的 CD 的信息。

Can you give me an idea how can I do that?

你能给我一个想法我该怎么做?

回答by Hego555

You can use JQuerywhich is a really nice framework to make the coding easy!

您可以使用JQuery,这是一个非常好的框架来简化编码!

You want to use the .click()event and the .show()function

你想用的。点击()事件和.show()函数

So you could have something like this

所以你可以有这样的东西

$("#clickme").click(function() {
     $("#hidden").show();
});

and for your html

和你的 html

<html>
<body>
<p id="clickme">Read More</p>
<p id="hidden" hidden>COOL STORY BRO</p>
</body>
</html>

Example

例子

回答by Gangnam

Suppose you have,

<div id="dvInfo">
 Here is your question and i am giving an answer. 
</div>
<a href="javascript:void()" id='see'>See more</a>

So,
In jQuery

$(document).ready(function(){
  var f_text = $('#dvInfo').html();
  $('#dvInfo').html($('#dvInfo').html().substring(0,8)+"...");
  $('#see').click(function(){
   $('#dvInfo').html(f_text);
  });
});

回答by preeti

html part

html部分

<asp:Button ID="btnread" runat="server" Text="Button" /> <div id="divinfo" style="display:none">More Info</div>

<asp:Button ID="btnread" runat="server" Text="Button" /> <div id="divinfo" style="display:none">More Info</div>

jquery part:

jquery部分:

    $(function () {
        $("#<%=btnread.ClientID %>").click(function () {
            $("div[id$=divinfo]").css("display", "block");
            return false;
        });
    });