简体   繁体   English

如何使用angular或jquery获取活动链接的名称

[英]How to get the name of an active link using angular or jquery

Please, help show the name of the active links to the inside toggle button. 请帮助显示指向内部切换按钮的活动链接的名称。

<div class="bs-example">
<!-- Trigger Button HTML -->
<a type="button" class="btn btn-primary" data-toggle="collapse" data-target="#toggleDemo" value="Toggle Button">Display here name of an active link </a>
<!-- Collapsible Element HTML -->
<div id="toggleDemo" class="collapse in">
<li><a href="<?php echo $h->vars['1_url_link']; ?>" class="btn <?php echo $h->vars['link_active']; ?>" role="button"><?php echo $h->lang["1_name_link"]; ?></a>  </li>
<li><a href="<?php echo $h->vars['2_url_link']; ?>" class="btn <?php echo $h->vars['link_active']; ?>" role="button"><?php echo $h->lang["2_name_link"]; ?></a></li>
<li><a href="<?php echo $h->vars['3_url_link']; ?>" class="btn <?php echo $h->vars['link_active']; ?>" role="button"><?php echo $h->lang["3_name_link"]; ?></a> </li>
</div>
</div>

It doesn't look like you're using AngularJS, so I'm going to give a jQuery answer: 看来您使用的不是AngularJS,因此我将给出一个jQuery答案:

Give your anchor button an id that you can target, such as: 为锚定按钮指定一个您可以定位的ID,例如:

<a type="button" class="btn btn-primary" data-toggle="collapse" data-target="#toggleDemo" value="Toggle Button" id="#togglebtn">Display here name of an active link </a>

Then you can set the text with the following: 然后,可以使用以下内容设置文本:

var btntext = $('.link_active').text();
$('#togglebtn').text(btntext);

EDIT: 编辑:

If you have multiple buttons with the .link_active class, then you can be more specific like: 如果.link_active类具有多个按钮,则可以更具体地像:

var btntext = $('#toggleDemo .link_active').text();
$('#togglebtn').text(btntext);

Think of jQuery selectors like you would use selectors in CSS. 想像jQuery选择器,就像您在CSS中使用选择器一样。 If you want the .link_active buttons to be red in one area and blue in another, you'd add another selector to be more specific. 如果您希望.link_active按钮在一个区域中为红色,而在另一个区域中为蓝色,则可以添加另一个选择器以更加具体。 Works the same in jQuery. 在jQuery中的工作原理相同。

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

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