【发布时间】:2016-01-20 01:03:51
【问题描述】:
我的父 div 包含一个隐藏的表单元素(输入):
$(document).ready(function () {
$('.parent').on('click', function (event) {
$(this).toggleClass('active');
$(this).find('.child').trigger('click');
});
$('.child').on('click', function (event) {
var theMsg = event.altKey ? 'true' : 'false';
$('.parent span').html(theMsg);
});
});
.parent {
width:100px;
height: 100px;
background: #eee;
}
.child {
display:none;
}
.active {
background: red !important;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class='parent'>
ALT: <span> </span>
<input class='child'>
</div>
当我的父点击处理程序被调用时,我会注意是否按下了 ALT 键。我正在尝试为隐藏的输入元素触发('click'),并传递 altKey 状态。我没有尝试过让这种情况发生。我错过了什么?
【问题讨论】: