Функционал не работает. Так как.... URL-адрес параметра Динамический Example.com/station=2,1,3 Возможно 2,3 / 3,1 / 3,2 Я хочу знать, что id будет знать динамический массив значений.
Пример получения параметра Url station 1,2,3 Кнопка станции 1 1 блок отображения и кнопка блока отображения станции 1,2 1,2 остальное нет и первая в активных данных на вкладке кнопок
<script>
document.getElementById("button1").style.display = "none";
document.getElementById("button2").style.display = "none";
document.getElementById("button").style.display = "none";
function getParameterByName(name, url) {
if (!url) url = window.location.href;
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, " "));
}
var station= getParameterByName('station');
var res = plan.split(" ",3);
i;
for(var i = 0; i < res.length; i++) {
res[i] = res[i].replace(/^\s*/, "").replace(/\s*$/, "");
if (res == 3) {
document.getElementById("button1").style.display = "block";
}else{
if (res == 2) {
document.getElementById("button2").style.display = "block";
}else{
document.getElementById("button3").style.display = "block";
for (i = 0; i < res.length; i++) {
res[i].style.display = "block";
}
}
}
}
</script> <ul class = "nav nav-tabs">
<li class = "active"><a data-toggle = "tab" href = "#dropdown1" id = "button1">button1</a></li>
<li><a data-toggle = "tab" href = "#dropdown2">button2</a></li>
<li><a data-toggle = "tab" href = "#dropdown3">button3</a></li>
</ul> да показать кнопки



![Безумие обратных вызовов в javascript [JS]](https://i.imgur.com/WsjO6zJb.png)


я надеюсь, что это сработает .. удачного кодирования :)
$(document).ready(() =>{
// showing the buttons if params is there
const hideShowButton = (elementHref) => {
$(`a[href='${elementHref}']`).css("display", "block");
}
let url; //window.location.href // Example.com/station=2,1,3
url = "Example.com/station=1,3";
let buttonsToBeShow = url.split(" = ")[1].split(",").map(o => parseInt(o));
buttonsToBeShow.forEach(o => {
switch(o){
case 1:
hideShowButton("#dropdown1")
break
case 2:
hideShowButton("#dropdown2")
break
case 3:
hideShowButton("#dropdown3")
break
default:
return;
}
})
})li a{
display:none;
}<script src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src = "https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/js/bootstrap.min.js"></script>
<link href = "https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.min.css" rel = "stylesheet"/>
<ul class = "nav nav-tabs">
<li class = "active"><a data-toggle = "tab" href = "#dropdown1" id = "button1">button1</a></li>
<li><a data-toggle = "tab" href = "#dropdown2">button2</a></li>
<li><a data-toggle = "tab" href = "#dropdown3">button3</a></li>
</ul> благодарить. Но это не похоже на кнопку, а на загрузочную вкладку
Я обновил ответ на основе вашего комментария. Пожалуйста, проверьте, если это нормально, вы можете просто принять его.
позвольте url; //window.location.href // Example.com/station=2,1,3 динамическая var station = getParameterByName ('station'); использовать unknown в jquery
Я не понял, о чем вы спрашиваете, чтобы получить значения станции?
поэтому на основе динамического идентификатора, который вам нужно показать кнопки, заключается в том, что вопрос