0

这是我当前的代码:

<select tabindex="2" id="resolvedformsel" name="resolved">
     <option selected="selected" value="yes">resolved</option>
     <option value="no">not resolved</option>
     <option value="mu">not a support question</option>
</select>
<input type="submit" value="Change" id="resolvedformsub" name="submit">

我想使用组合键(如 Ctrl+Alt+1)来选择“已解决”并立即执行“提交”。我正在为支持论坛进行此修改,并且使用热键来标记已解决的线程会很方便。

我不包括 jQuery!它必须是纯 JS 解决方案。有任何想法吗?

换句话说:什么是 JS 相当于 jQuery 的 keypress/keydown?

4

2 回答 2

2

It would be better if you had a form, but you still can use:

window.addEventListener('keypress', function (event) {
    if (event.which == 13 && event.ctrlKey) { // Ctrl + Enter
        document.getElementById('resolvedformsel').options[0].selectected = true;
        document.getElementById('resolvedformsub').click();
    }
})
于 2012-07-24T08:05:54.740 回答
0

Key combinations are not easy and some keys are reserved. So it might not work. I would try it that way: Check in the jQuery source how they are catching the metaKey property of the event object. Take a look at some plugins handling events with key combinations. Hopefully this gives you some "inspiration".

于 2012-07-24T08:04:11.560 回答