Событие onkeypress в modalDialog

у меня есть этот код:

<a href="#openModal">Open Modal</a>
<div id="openModal" class="modalDialog">
<div>
    <a href="#close" title="Close" class="close">X</a>
    <h2>Modal Box</h2>
    <input type="radio" value="rdRec" checked="checked" />Rec
    <input type="radio" value="rdPot" />Pot
    <input type="button" id="btnOk" value="ok" onkeypress="checkey();">
</div>

<script type="text/javascript">
  function checkey()
  {
     var code = window.event.keyCode;
     if(code == 13) 
     {      
     document.getElementById('btnOk').click();
     return false;
     }
  }
</script>

All i want is when the popup is open and the radio button Rec is select/checked i want to click on enter key and automatically trigger the btnOk...


person Erased    schedule 21.02.2016    source источник
comment
Я думаю, что ответ, который вы ищете, находится в этом ранее отвеченном вопросе: stackoverflow.com/questions/382171/   -  person DenizEng    schedule 21.02.2016
comment
Возможный дубликат не работает обнаружение нажатия клавиши в модальном диалоговом окне   -  person Vic Seedoubleyew    schedule 18.07.2019


Ответы (1)


Я думаю, что ответ, который вы ищете, находится в этом ранее отвеченном вопросе: Используйте Javascript, чтобы изменить отправку, которая активируется при нажатии клавиши ввода

document.onkeypress = processKey;

function processKey(e)
{
    if (null == e)
        e = window.event ;
    if (e.keyCode == 13)  {
        document.getElementById("btnOk").click();
    }
}
person DenizEng    schedule 21.02.2016