[英]HTML Radio Button Javascript
http://jsfiddle.net/8sbt5oua/8/
我想讓我的代碼每次只專注於少數幾個。
除了所有人,誰能幫助我?
<input id="01" type="radio">
<input id="02" type="radio">
<input id="03" type="radio">
<input id="04" type="radio">
<input id="05" type="radio">
<input id="06" type="radio">
var btn = document.getElementById("02");
setInterval(function() {
var list=document.getElementsByTagName("input");
for (i=0;i<list.length;i++) {
btn = list[i];
btn.checked == false ? btn.setAttribute("checked", "checked") : btn.removeAttribute("checked");
}
}, 500);
這是JsFiddle: http : //jsfiddle.net/8sbt5oua/10/
首先有兩個要閃爍的數組。
var arr1 = [0,1,2];
var arr2 = [3,4,5];
您還需要一個在兩者之間切換的全局變量。
var use_first = true;
然后,您要使用切換變量來確定哪個打開和關閉。
let remove;
let checked;
if (use_first)
{
checked = arr1;
remove = arr2;
}
else
{
checked = arr2;
remove = arr1;
}
而且我認為foreach可以自我解釋,因為它們基本上就是您的代碼。
編輯:
remove.forEach(function(item, index)
{
btn = list[item];
btn.removeAttribute("checked");
});
checked.forEach(function(item, index)
{
btn=list[item];
btn.setAttribute("checked", "checked");
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.