<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<!-- 打开弹窗按钮 -->
<button onclick="test()">获取当前系统</button>
<button class="urlJump" data-type="1" >location.href</button>
<button class="urlJump" data-type="2" >top.window.location</button>
<div onclick="outdoor()" style="border: 1px solid red;width: 200px;height: 100px" >
<p>最外层是一个父类的div</p>
<div id="btn">
</div>
</div>
<script type="text/javascript">
$(function () {
$(".urlJump").on("click",function(){
var type=$(this).attr("data-type");
if(type =="" || type == null){
return;
}
if(type == "1"){
location.href="https://www.baidu.com/";
}else {
top.window.location="https://www.iqiyi.com/";
}
});
showbtn();
});
function test() {
var ua = navigator.userAgent;
console.log(ua);
if(ua.indexOf("Windows NT 6.1")!=-1) {
alert('您使用的是Win7系统!');
} else {
alert('不是win7 ');
}
}
function showbtn(){
$("#btn").empty();
var content='<button data-id="hihi" onclick="reload(event,this)">div里的button</button>';
$("#btn").append(content);
}
function outdoor(){
location.href="https://www.baidu.com/";
}
function reload(event,obj){
stopEvent(event);
var bool=window.confirm("确定要取消吗?");
if(bool){
alert("取消");
var val = $(obj).attr("data-id");
}
}
function stopEvent(event){ //阻止冒泡事件
//取消事件冒泡
var e=arguments.callee.caller.arguments[0]||event; //若省略此句,下面的e改为event,IE运行可以,但是其他浏览器就不兼容
if (e && e.stopPropagation) {
// this code is for Mozilla and Opera
e.stopPropagation();
} else if (window.event) {
// this code is for IE
window.event.cancelBubble = true;
}
}
</script>
</body>
</html>