【发布时间】:2016-02-17 02:56:28
【问题描述】:
如何使用关闭按钮终止此弹出窗口?还是某种div?我试过这样:
jQuery.ajax( {
url: '//freegeoip.net/json/',
type: 'POST',
dataType: 'jsonp',
success: function(location) {
jQuery('#city').html(location.city);
jQuery('#region-code').html(location.region_code);
jQuery('#region-name').html(location.region_name);
jQuery('#areacode').html(location.areacode);
jQuery('#ip').html(location.ip);
jQuery('#zipcode').html(location.zipcode);
jQuery('#longitude').html(location.longitude);
jQuery('#latitude').html(location.latitude);
jQuery('#country-name').html(location.country_name);
jQuery('#country-code').html(location.country_code);
}
} );
jQuery.ajax( {
url: '//freegeoip.net/json/',
type: 'POST',
dataType: 'jsonp',
success: function(location) {
if (location.region_name === 'Utah') {
$('#message').parent().show();
}
else{
$(".close").click(function(){
$("#message").hide();
});
}
}
} );
而且它不起作用。通过使用 .hide();我假设它会自动隐藏div?
这是用于显示此弹出窗口的 HTML。弹出窗口使用地理定位,来检测位置和弹出窗口,我需要它然后通过点击关闭。
<!doctype html>
<html lang="en">
<head>
<title>This is a popup</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
<style type="text/css">
body
{
background: url(1.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
#message
{
width:516px;
height:508px;
margin:0 auto;
background-image: url(test.jpg);
position:absolute;
left:50%;
top:50%;
margin-left:-250px;
margin-top:-250px;
transition: 0.5s;
}
</style>
</head>
<body>
<div style="display:none;">
<div id="message">
<a class="close" href="/">Cancel</a>
</div>
</div>
<script src="js/scripts.js"></script>
</body>
</html>
【问题讨论】: