如果每个元素都有自己的tabindex
,如下所示:
<a href="http://example.com" tabindex="3">Link</a>
<input type="text" tabindex="2">
<select tabindex="5">
<option>Option A</option>
<option>Option B</option>
<option>Option C</option>
</select>
<textarea tabindex="4">Hello world</textarea>
<button tabindex="1" id="Btn">Button</button>
现在,我向button[id=Btn]
添加了一个事件,该事件将所有元素“tabindex
设置为-1
,如下所示:
document.getElementById("Btn").addEventListener("click", function(){
var allElement = document.querySelectorAll("a,area,button,input,object,select,textarea");
for(var i = 0; i < allElement.length; i++){
allElement[i].setAttribute("tabindex",-1);
}
});
点击button[id=Btn]
后,如何将所有元素重置为原始tabindex
?
答案 0 :(得分:3)
将当前function extractParameters(args) {
function getCase(arg, key) {
return arg.match(new RegExp(`${key}=(.*)`)) || {};
}
args.forEach((arg) => {
console.log("arg: " + arg);
let match;
switch (arg) {
case (match = getCase(arg, "--user")).input:
case (match = getCase(arg, "-u")).input:
userName = match[1];
break;
case (match = getCase(arg, "--password")).input:
case (match = getCase(arg, "-p")).input:
password = match[1];
break;
case (match = getCase(arg, "--branch")).input:
case (match = getCase(arg, "-b")).input:
branch = match[1];
break;
}
});
};
保存在tabindex
属性中,并在需要时使用它恢复原始tabindex值:
data-
&#13;
var allElement = document.querySelectorAll("a,area,button,input,object,select,textarea");
document.getElementById("Btn").addEventListener("click", function() {
for (var i = 0; i < allElement.length; i++) {
allElement[i].setAttribute("data-tabindex", allElement[i].getAttribute("tabindex"));
allElement[i].setAttribute("tabindex", -1);
}
});
document.getElementById("BtnRes").addEventListener("click", function() {
for (var i = 0; i < allElement.length; i++) {
allElement[i].setAttribute("tabindex", allElement[i].getAttribute("data-tabindex"));
allElement[i].removeAttribute("data-tabindex", -1);
}
});
&#13;