0

shift如果在用户单击时按下,我将尝试打开新窗口,如果在用户单击时打开enter新选项卡ctrl。部分有效,shiftctrl部分不...

var ctrlPressed = false;
var shiftPressed = false;
var stb = null;
function onload() {
stb = document.getElementById("searchTextBox");
}
    function enter(e) {

        if (e.keyCode == 13) {
            if (!ctrlPressed && !shiftPressed) {
            window.location = "http://search.yahoo.com/search?p=" + encodeURI(stb.value) + "&fr2=sb-top&fr=404_web&pqstr=" + encodeURI(stb.value);
            }
            else if (ctrlPressed) {
            window.open("http://search.yahoo.com/search?p=" + encodeURI(stb.value) + "&fr2=sb-top&fr=404_web&pqstr=" + encodeURI(stb.value));
            }
            else if (shiftPressed) {
            window.open("http://search.yahoo.com/search?p=" + encodeURI(stb.value) + "&fr2=sb-top&fr=404_web&pqstr=" + encodeURI(stb.value), "_blank");
            }
        }
    }
    function searchdown(e) {
        if (e.keyCode == 17) {
            ctrlPressed = true;
        }
        else if (e.keyCode == 16) {
            shiftPressed = true;
        }
    }
    function searchup(e) {
        if (e.keyCode == 17) {
            ctrlPressed = false;
        }
        else if (e.keyCode == 16) {
            shiftPressed = false;
        }
    }

我也不能使用jQuery...

4

1 回答 1

2

您是否知道event.ctrlKey会告诉您控制键是否被按住?

于 2012-04-10T01:09:30.270 回答