求帮助,jquery点击按钮模拟键盘输入退格键
你好!!
1
2
1. Ctrl+S 组合键应该是在某个事件中被定义的,比如说:某个元素的keydown事件中,因此只需在按钮的<a href="https://www.baidu.com/s?wd=click%E4%BA%8B%E4%BB%B6&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1YLnHwhP1N-njIbmynYn1Ph0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3ErHD3nWR1PHfsPHD3P1T3PWb4" target="_blank" class="baidu-highlight">click事件</a>中,触发该事件就可以了;
2. 按钮的<a href="https://www.baidu.com/s?wd=click%E4%BA%8B%E4%BB%B6&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1YLnHwhP1N-njIbmynYn1Ph0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3ErHD3nWR1PHfsPHD3P1T3PWb4" target="_blank" class="baidu-highlight">click事件</a>中,需要设置下事件对象的属性,比如:event.keyCode=83 && event.ctrlKey=true; 然后将该event对象传入keydown事件中;
可以参考以下代码:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<script type="text/javascript">
$(document).ready(function(){
$(window).keydown(function(e){
if(e.keyCode==83&&e.ctrlKey){
e.preventDefault();
alert("按下了ctrl+S`````");
}
});
var e = jQuery.Event("keydown");
e.keyCode=83,e.ctrlKey=true;
$("button").click(function(){
$(window).trigger(e);
});
});
</script>