达到你所说的效果很简单
<input type="button" onclick="Show()" value="显示" /><div id="ceng" style="position:absolute width: 100% height: 100% top: 0 left: 0 display: none">
<div onclick="Hide()" style="position:absolute width: 100% height: 100% top: 0 left: 0 background-color: rgba(0, 0, 0, 0.4)"></div>
<div style="position:relativemargin:auto width: 100pxheight:100pxbackground-color:white">
</div>
</div> <script type="text/javascript">
function Show() {
document.getElementById("ceng").style.display = "block"
}
function Hide() {
document.getElementById("ceng").style.display = "none"
}
</script>
设置一个隐藏层,点击按钮的时候改变隐藏层的display属性,将隐藏层显示出来。
再给隐藏层设置一个Hide()点击方法,点击隐藏层再次隐藏。
望采纳!
最常用的方法就是通过触摸事件来控制键盘的隐藏,代码如下:-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
[textFiled resignFirstResponder]
}
或者自定义触摸手势来控制键盘的隐藏,代码如下:
- (void)viewDidLoad
{
[super viewDidLoad]
UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(keyboardHide:)]
//设置成NO表示当前控件响应后会传播到其他控件上,默认为YES。
tapGestureRecognizer.cancelsTouchesInView = NO
//将触摸事件添加到当前view
[self.view addGestureRecognizer:tapGestureRecognizer]
}
-(void)keyboardHide:(UITapGestureRecognizer*)tap{
[textFiled resignFirstResponder]
}
可以参考这个!document.onclick = function(){
//隐藏层代码
}
div.onclick = function(oEvent){
//取消冒泡
oEvent = oEvent || window.event
if(document.all){
oEvent.cancelBubble = true
}else{
oEvent.stopPropagation()
}
}