单击按钮时显示/隐藏href链接

本文关键字:隐藏 href 链接 显示 按钮 单击 | 更新日期: 2023-09-27 18:05:19

在按钮上单击会生成详细信息页面。我有一个href链接,当点击它时,它会在页面中导航。但在页面加载时,应该只有按钮(点击它会生成主页(,但href链接也会出现。

我想在页面加载时应该只有一个按钮,点击它就会出现href链接。并且在单击另一个按钮时应该会消失。

Scrip:

$(document).ready(function () {
        $('#priorityC').hide();
        $('#perC').hide();
        });
    $('#btnAnalyse').click(function () {
        $('#priorityC').show();
        $('#perC').show();
    });

这是按钮:

<asp:ImageButton ID="btnAnalyse" runat="server" OnClick="btnAnalyse_Click"/>

这是href链接,我只想在点击上面的按钮时显示:

<a href="Homepage.aspx#perC">Hourly Detailed Priority Representation</a>
<a name="priorityPer">
<div id="perC" class="center">
<asp:Label ID="lblDPTC" runat="server" Text="Detailed Percentage     representation of Ticket Count" Visible="false"></asp:Label>
</div>
</a>

它在页面加载时隐藏,但在按钮单击时不显示。

单击按钮时显示/隐藏href链接

<asp:ImageButton ID="btnAnalyse" runat="server" ImageUrl="image1.jpg" OnClick="btnAnalyse_Click"/>

<a href="Homepage.aspx#p" id="linkid" runat="server">Hourly Detailed Priority Representation</a>
<a name="priorityPer">
<div id="per" class="center">
<asp:Label ID="lblDPTC" runat="server" Text="Detailed Percentage     representation of Ticket Count" Visible="false"></asp:Label>
</div>
</a>

和您的后端页面(codepage.cs(

 protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        linkid.Visible = false;
    }
}
protected void btnAnalyse_Click(object sender, ImageClickEventArgs e)
{
    if (linkid.Visible == false)
    {
        linkid.Visible = true;
    }
}
 protected void btnAnother_Click(object sender, EventArgs e)
    {
     linkid.Visible = false;
    }

您可以在div中编写href链接,使用Jquery可以相应地隐藏和显示div。

代码片段

<script>
// On load hide the div
$(document).ready(function(){
  $('#MYDIV').hide();
};
// call this function on button click to show/hide the link
function showHideLink(buttonName)
{
  if(buttonName=='blah')
  {
    $('#MYDIV').hide();
  }
  else
  {
    $('#MYDIV').show();
  }
}
</script>

希望这能有所帮助。

test.aspx

<li class="nav-item">
   <a class="nav-link" id="AdminFaciliy" href="charts.html" runat="server">
   <i class="fas fa-fw fa-user">
</i>

text.aspx.cs

if (Utype.Trim().ToUpper()=="ADMIN"){               
  AdminFaciliy.Visible = true;
}