Javascript 在表标题中单击Ctrl键向上键事件
我想用Javascript 在表标题中单击Ctrl键向上键事件,javascript,jquery,html-table,Javascript,Jquery,Html Table,我想用生成keyup事件。如果我在区域中单击,单击事件将在那里填充,但当我释放CTRL键并在区域中单击时,我的要求是生成事件,我将使用以下代码 <html> <head> <script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"&
生成keyup事件。如果我在
区域中单击,单击事件将在那里填充,但当我释放CTRL键并在
区域中单击时,我的要求是生成事件,我将使用以下代码
<html>
<head>
<script
src="https://code.jquery.com/jquery-3.2.1.min.js"
integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
crossorigin="anonymous"></script>
</head>
<body>
<table border="2">
<th>rollno</th>
<th>name</th>
<tr>
<td>4567</td>
<td>john</td>
</tr>
</table>
</body>
<script>
$('th').click(function(){
alert("yes its working");
});
</script>
<script>
$('th').on('keyup', function(e) {
if (e.keyCode ==17)
{
alert("OOps! ctr+click release not working");
}
});
</script>
</html>
罗尔诺
名称
4567
厕所
$('th')。单击(函数(){
警惕(“是的,它正在工作”);
});
$('th')。关于('keyup',函数(e){
如果(e.keyCode==17)
{
警报(“OOps!ctr+点击释放不工作”);
}
});
像那样吗
$('th').click(function(e){
if(e.ctrlKey){
alert("yes its working");
}
});
编辑:
$( 'th' ).click( function ( e ) {
if ( e.ctrlKey ) {
$( window ).on( 'keyup' , function () {
alert( "yes its working" );
$( window ).off( 'keyup' );
} );
}
else {
alert( 'nop' );
}
} );
所以,基本上你想要一个事件,当它点击
th
时,鼠标仍然是down
,而ctrl
键是up
?或者你想要一个事件ctrl+click
?看看我的要求我想要弹出用户点击并按下ctrl键,然后当用户释放ctrl键时是否仍然点击不重要弹出窗口应该在那里这是什么我想要在ctrl键上释放的动作而不是ctrl+CLICKcheck这个小提琴亲爱的这将显示警报当我用CTRL键单击时显示消息,但当我在CTRL+click后释放CTRL键时显示消息我已编辑代码。是,现在正在工作
$(document).on('keyup',function(event){
if(event.which=="17"){
cntrlIsPressed = true;
}
else{cntrllsPressed=false;}
});
$('th').on('click ', function(e) {
if (cntrllsPressed==true)
{
alert("OOps! ctr+click release not working");
}
});
$(document).on('keydown',function(event){
cntrlIsPressed =false;
});