[英]Bootstrap Modal focus issue
我有引導模式,其中我有桌子,我想通過按下面的向上鍵和向下鍵專注於行,這是我在js中的代碼,但焦點僅在IE中不起作用
var _checkKey = function (e) {
var event = window.event ? window.event : e;
if (event.keyCode === 13) // the enter key code
{
$("tr:focus").click();
event.preventDefault();
return;
}
if (event.keyCode === 40) { //down
event.preventDefault();
var idx = $("tr:focus").attr("tabindex");
if (!idx)
idx = 0;
else
idx++;
$("tr[tabindex=" + idx + "]").focus();
}
if (event.keyCode === 38) { //up
event.preventDefault();
var idx = $("tr:focus").attr("tabindex");
idx--;
$("tr[tabindex=" + idx + "]").focus();
}
}
該函數通過keydown事件調用
波紋管是用於引導程序模式的html代碼,
相同的代碼在chrome和IE 11中有效,但在引導程序模型中則無效
<div class="modal fade in" id="commonModal" role="dialog" aria-hidden="false" style="display: block;"> <div class="modal-dialog modal-lg"> <div class="modal-content visible-o-flow"> <div class="modal-header"> <h3 class="modal-title fl" id="Title">Header</h3> <button class="close wa m-0 fr" aria-label="Close" type="button" data-dismiss="modal"> <span aria-hidden="true">×</span> </button> </div> <div class="modal-body fw" id="miscDiv"> <form class="fh" id="msform"> <div class="col-md-12 p-0"> <div id="lookupDiv" style="left: 191.09px; top: 153.68px; width: 538.4px; display: block; position: absolute; z-index: 9000;"> <table class="table table-responsive table-fixed table-hover"> <thead> <tr> <th class="col-md-3">Code</th> <th class="col-md-9">Description</th> </tr> </thead> <tbody id="lookupTable"> <tr tabindex="0" style="cursor: pointer;"><td>729</td><td>SAMOA</td></tr> <tr tabindex="1" style="cursor: pointer;"><td>209</td><td>AFGHANISTAN</td></tr> <tr tabindex="2" style="cursor: pointer;"><td>265</td><td>AZERBAIJAN</td></tr> <tr tabindex="3" style="cursor: pointer;"><td>201</td><td>IRAN (ISLAMIC REPUBLIC OF)</td></tr> <tr tabindex="4" style="cursor: pointer;"><td>235</td><td>NEPAL</td></tr> <tr tabindex="5" style="cursor: pointer;"><td>645</td><td>PARAGUAY</td></tr> <tr tabindex="6" style="cursor: pointer;"><td>347</td><td>SIERRA LEONE</td></tr> <tr tabindex="7" style="cursor: pointer;"><td>267</td><td>TAJIKISTAN</td></tr> <tr tabindex="8" style="cursor: pointer;"><td>233</td><td>VIET NAM</td></tr> <tr tabindex="9" style="cursor: pointer;"><td>309</td><td>CAMEROON</td></tr> <tr tabindex="10" style="cursor: pointer;"><td>727</td><td>MARSHALL ISLANDS</td></tr> </tbody> </table> </div> </div> </form> </div> </div> </div> </div>
嘗試將其放在var事件行之后:
var event = window.event ? window.event : e;
var kCode = event.keyCode || event.which;//for IE, FireFox and Chrome
if (kCode === 13)...
至少對我來說,可以在Chrome和FireFox中使用
我有一個相同的問題,但沒有得到任何宗教解決方案,因此我經歷了
我將此代碼放在模式點擊事件上。
setTimeout(()=>{
document.getElementById("id").focus();
},9000);
//id is the name of element where you want to put your focus
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.