简体   繁体   English

如何在单击其他元素时编辑所有href的标签?

[英]How to edit all the href's tags on click other element?

I have a navbar width links to all the months with a get attribute to the month and the year. 我有一个导航栏宽度链接到所有月份,并带有指向月份和年份的get属性。

<a href="?ano=2018&mes=09" class="change">Sep</a>
<a href="?ano=2018&mes=10" class="change">Oct</a>
<a href="?ano=2018&mes=11" class="change">Nov</a>
<a href="?ano=2018&mes=12" class="change">Dec</a>

I want to add another get attr to all the tags when I'll click another element in the page, something like this: 当我单击页面中的另一个元素时,我想向所有标签添加另一个get attr,如下所示:

<button onclick="add-to-href('&element=1')on-every('.change')">Element 1</button>

<button onclick="add-to-href('&element=2')on-every('.change')">Element 2</button>

I don't need so much to change the tag when clic other button, just with an adding element i'll be glad =) 当单击其他按钮时,我不需要太多更改标签,只需添加元素,我将很高兴=)

The final result on the whole page should look like this: 整个页面上的最终结果应如下所示:

<a href="?ano=2018&mes=09&element=1" class="change">Sep</a>
<a href="?ano=2018&mes=10&element=1" class="change">Oct</a>
<a href="?ano=2018&mes=11&element=1" class="change">Nov</a>
<a href="?ano=2018&mes=12&element=1" class="change">Dec</a>

Sorry for my english 对不起我的英语不好

add this in your onClick function 将此添加到您的onClick函数中

document.querySelectorAll(".change").forEach(v => {
 v.setAttribute('href', v.getAttribute('href') + '&element=1');
});

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

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