点击右键和按钮进行显示隐藏div
程序员文章站
2022-03-02 21:13:25
...
代码如下:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style type="text/css">
*{cursor: pointer;}
#nav
{
width: 200px;
height: 500px;
background-color: red;
border: 1px solid red;
}
#nav2
{
height: 30px;
}
#nav3
{
height: 30px;
}
body{
width: 100%;
height: 100%;
}
</style>
<script type="text/javascript" src="jquery-1.12.4.min.js" ></script>
<script type="text/javascript">
window.onclick = function () {
var ua =navigator.userAgent.toLowerCase();
if(/(iPhone|iPad|iPod|iOS)/i.test(ua)){
alert("winua");
if (/(iPhone)/i.test(navigator.userAgent)) { alert("iPhone-w"); }
else if (/(iPad)/i.test(navigator.userAgent)) { alert("iPad-w"); }
else if (/(iPod)/i.test(navigator.userAgent)) { alert("iPod-w"); }
else if (/(iOS)/i.test(navigator.userAgent)) { alert("iOS-w"); }
}
//要隐藏的 div 外点击事件
// alert("点击div外侧");
if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {
// alert(navigator.userAgent);
// window.location.href ="iPhone.html";
// alert("iPhone|iPad|iPod|iOS");
if (/(iPhone)/i.test(navigator.userAgent)) { alert("iPhone-w"); }
else if (/(iPad)/i.test(navigator.userAgent)) { alert("iPad-w"); }
else if (/(iPod)/i.test(navigator.userAgent)) { alert("iPod-w"); }
else if (/(iOS)/i.test(navigator.userAgent)) { alert("iOS-w"); }
} else if (/(Android)/i.test(navigator.userAgent)) {
// alert(navigator.userAgent);
// window.location.href ="Android.html";
alert("Android-w");
} else {
// alert(navigator.userAgent);
alert("pc-w");
// window.location.href ="pc.html";
};
var ev = window.event || ev;
hide('false', ev, 'nav');
}
$(function($) {
$(document).delegate("body", "click", function(e) {
alert(1);
bodyfu();
});
});
function bodyfu() {
var ua = navigator.userAgent.toLowerCase();
if (/(iPhone|iPad|iPod|iOS)/i.test(ua)) {
alert(navigator.userAgent);
if (/(iPhone)/i.test(navigator.userAgent)) { alert("iPhone-body"); }
else if (/(iPad)/i.test(navigator.userAgent)) { alert("iPad-body"); }
else if (/(iPod)/i.test(navigator.userAgent)) { alert("iPod-body"); }
else if (/(iOS)/i.test(navigator.userAgent)) { alert("iOS-body"); }
}else if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {
// alert(navigator.userAgent);
// window.location.href ="iPhone.html";
alert("iPhone|iPad|iPod|iOS");
if (/(iPhone)/i.test(navigator.userAgent)) { alert("iPhone-body"); }
else if (/(iPad)/i.test(navigator.userAgent)) { alert("iPad-body"); }
else if (/(iPod)/i.test(navigator.userAgent)) { alert("iPod-body"); }
else if (/(iOS)/i.test(navigator.userAgent)) { alert("iOS-body"); }
} else if (/(Android)/i.test(navigator.userAgent)) {
// alert(navigator.userAgent);
// window.location.href ="Android.html";
alert("Android.html-body");
} else {
// alert(navigator.userAgent);
alert("pc.html-body");
// window.location.href ="pc.html";
};
var ev = window.event || ev;
hide('false', ev, 'nav');
}
document.onclick = function (ev) {
var ua = navigator.userAgent.toLowerCase();
if (/(iPhone|iPad|iPod|iOS)/i.test(ua)) {
alert(navigator.userAgent);
if (/(iPhone)/i.test(navigator.userAgent)) { alert("docua-iPhone"); }
else if (/(iPad)/i.test(navigator.userAgent)) { alert("docua-iPad"); }
else if (/(iPod)/i.test(navigator.userAgent)) { alert("docua-iPod"); }
else if (/(iOS)/i.test(navigator.userAgent)) { alert("docua-iOS"); }
}else if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {
// alert(navigator.userAgent);
// window.location.href ="iPhone.html";
alert("iPhone|iPad|iPod|iOS");
if (/(iPhone)/i.test(navigator.userAgent)) { alert("iPhone"); }
else if (/(iPad)/i.test(navigator.userAgent)) { alert("iPad"); }
else if (/(iPod)/i.test(navigator.userAgent)) { alert("iPod"); }
else if (/(iOS)/i.test(navigator.userAgent)) { alert("iOS"); }
} else if (/(Android)/i.test(navigator.userAgent)) {
// alert(navigator.userAgent);
// window.location.href ="Android.html";
alert("Android.html");
} else {
// alert(navigator.userAgent);
alert("pc.html");
// window.location.href ="pc.html";
};
var ev = window.event || ev;
hide('false', ev, 'nav');
}
function hide(CheckShow, evt, id) {
var obj = document.getElementById(id);
var target = evt.target ? evt.target : evt.srcElement;
if (CheckShow == "true") {
//首先排除事件的
obj.style.display = "block";
return;
} else
if (target.id == "nav2" || target.id == "nav3" || target.id == "anani")
return;
else
obj.style.display = "none";
}
function Show() {
hide('true', 0, 'nav');
}
function hiden() {
document.getElementById("nav").style.display = "none";
}
</script>
</head>
<body>
<div id="nav">
</div>
<div id="nav2" onclick="Show();">
show</div>
<div id="nav3" onclick="hiden();">
hiden</div>
</body>
</html>
推荐阅读
-
Angular实现点击按钮控制隐藏和显示功能示例
-
js或jquery实现点击某个按钮或元素显示div,点击页面其他任何地方隐藏div
-
【MATLAB】在MATLAB中利用GUI编写加法计算器,要求:通过两个编辑文本框实现两个数字的输入,点击“开始计算”按钮进行计算,并在用于结果显示的静态文本框中实现两输入数字的和的显示
-
js或jquery实现点击某个按钮或元素显示div,点击页面其他任何地方隐藏div
-
点击按钮显示一个div,div之外的地方隐藏,之内的地方不隐藏
-
两个单选按钮,点击其中一个隐藏或显示其他的div
-
两个单选按钮(一个是,一个否 ),一个div层,实现点击隐藏,显示div
-
点击按钮显示和隐藏标签
-
用JQuery实现点击按钮来显示/隐藏某个div
-
React 点击按钮显示div与隐藏div