Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Onclick和Onkeypress_Javascript_Html_Onclick_Onkeydown_Onkeypress - Fatal编程技术网

Javascript Onclick和Onkeypress

Javascript Onclick和Onkeypress,javascript,html,onclick,onkeydown,onkeypress,Javascript,Html,Onclick,Onkeydown,Onkeypress,我的剧本有问题,我不来了。 当我点击“链接5”窗口出现。然后我只有一次机会关闭这个窗口,按下“关闭”按钮。 我想要另一个函数,即onkeypress函数。 当我按下Esc键时,窗口也应关闭。我希望你能帮助我 <li onClick="return pop('pop')" id="stream">Link 5</li> <div id="pop" class="parentDisable" onselectstart="return false" on

我的剧本有问题,我不来了。 当我点击“链接5”窗口出现。然后我只有一次机会关闭这个窗口,按下“关闭”按钮。 我想要另一个函数,即onkeypress函数。 当我按下Esc键时,窗口也应关闭。我希望你能帮助我

<li onClick="return pop('pop')" id="stream">Link 5</li>
        <div id="pop" class="parentDisable" onselectstart="return false" onselectstart="return false">
            <table border="1" id="popup">
                <tr>
                    <td>
                        <a href="" onClick="return hide('pop')" style="float: right; margin: 4px;">
                            <img src="http://www.imgbox.de/users/Metraax/close.png" />
                        </a>
                    </td>
                </tr>
                <tr>
                    <td>
                        <h2>Fenster ge&ouml;ffnet</h2>
                    </td>
                </tr>
                <tr>
                    <td>height: auto;</td>
                </tr>
            </table>
        </div>
        <script type="text/javascript">
        function pop(div)
        {
        document.getElementById(div).style.display='block';
        return false
        }
        function hide(div)
        {
                           if (e.keycode == '27')
                    {document.getElementById(div).style.display='none';}
        document.getElementById(div).style.display='none';
        document.getElementById(div).style.display='none';
        return false
        }
        </script>

    <style>

    .parentDisable {
        z-index:999;
        width:100%;
        height:100%;
        display:none;
        position: absolute;
        top:0;
        left:0;
        background-color: rgba(204, 204, 204, 0.4);
        color: #aaa;
        filter: alpha(opacity=50);
    }
    #popup {
        width: 44.48%;
        position: absolute;
        top: 200px;
        left: 27.76%;
        color: #000;
        background-color: #C4C4C4;
        border-radius: 5px;
        box-shadow: 0px 0px 20px gray;
    }
    #popup tr td h2 {
        float: left;
        font-size: 20px;
    }
    #popup tr {
        cursor: default;
    }
    </style>
链接5 芬斯特·geö;ffnet 高度:自动; 函数pop(div) { document.getElementById(div.style.display='block'; 返回错误 } 函数隐藏(div) { 如果(e.keycode=='27') {document.getElementById(div.style.display='none';} document.getElementById(div.style.display='none'; document.getElementById(div.style.display='none'; 返回错误 } .parentDisable{ z指数:999; 宽度:100%; 身高:100%; 显示:无; 位置:绝对位置; 排名:0; 左:0; 背景色:rgba(204、204、204、0.4); 颜色:#aaa; 过滤器:α(不透明度=50); } #弹出窗口{ 宽度:44.48%; 位置:绝对位置; 顶部:200px; 左:27.76%; 颜色:#000; 背景色:#C4; 边界半径:5px; 盒影:0px 0px 20px灰色; } #弹出tr td h2{ 浮动:左; 字体大小:20px; } #弹出式tr{ 游标:默认值; }
您可以在jQuery中使用此代码:

$(document).keyup(function(e) {    
  if (e.keyCode == 27) { <YOUR CODE HERE> }   // esc
});
$(文档).keyup(函数(e){
如果(e.keyCode==27){}//esc
});
类似这样的内容:

function pop(div) {
    var d = document.getElementById(div);
    d.style.display = 'block';

    if (document.addEventListener) {
        document.addEventListener ("keyup", function(e) {
            onEsc(e, d);
        }, false);
    }else{
        if (document.attachEvent)
            button.attachEvent ("keyup", function(e) {
                onEsc(e, d);
            });
    }
    return false
}

function hide(div) {
    document.getElementById(div).style.display = 'none';
    return false
}

function onEsc(event, elem) {
    if ( event.which == null && (event.charCode != null || event.keyCode != null) ) {
        event.which = event.charCode != null ? event.charCode : event.keyCode;
    }
    if (event.which === 27) {
        elem.style.display = 'none';
        document.removeEventListener("keyup");
    }
}

前面的问题可能会有所帮助。为什么你有一个没有UL的LI元素,而有一个DIV作为兄弟,有些不对劲呢?呃-表layout@Selfproblemmade-不客气,您也可以在较旧的浏览器中编辑它。如果我在javascript方面遇到问题,您可以成为我的联系人吗?