使用 Ajax/Javascript 按下按钮时弹出通知弹出窗口

Notification Popup on button press using Ajax/Javascript?

本文关键字:通知 窗口 按钮 Ajax Javascript 使用      更新时间:2023-09-26

我目前正在制作一个包含通知的网站,但我不太确定如何在按下按钮时显示它们。诸如"显示天气"之类的内容将在底角的某个位置显示通知。

https://i.stack.imgur.com/v8pEd.png

它能做到多难?真的可能吗?

下面是一个通过单击按钮显示天气的示例。使用此插件--- http://simpleweatherjs.com/

.HTML

<div id="weather"></div>
<input type="submit" id="Show" value="Current Weather" />

简讯

// Docs at http://simpleweatherjs.com
$(document).ready(function() {
    $("#weather").hide();
  $.simpleWeather({
    location: 'Nicosia, CY',
    woeid: '',
    unit: 'f',
    success: function(weather) {
      html = '<h2><i class="icon-'+weather.code+'"></i> '+weather.temp+'&deg;'+weather.units.temp+'</h2>';
      html += '<ul><li>'+weather.city+', '+weather.region+'</li>';
      html += '<li class="currently">'+weather.currently+'</li>';
      html += '<li>'+weather.wind.direction+' '+weather.wind.speed+' '+weather.units.speed+'</li></ul>';
      $("#weather").html(html);
    },
    error: function(error) {
      $("#weather").html('<p>'+error+'</p>');
    }
  });
});
$("#Show").click(function(){
  $("#weather").show();
});

演示

http://jsfiddle.net/LW3S9/4/

这是使用 Jquery UI 的弹出窗口的演示。

http://jsfiddle.net/LW3S9/5/

因此,您将需要单击功能,如果某些特定内容,例如使用插入进行天气。

可以显示。

click()用于按钮按下事件。

$("button_reference").click(function(){
   // do your notification-related stuff here
});

您可以使用单击事件来显示弹出窗口,如果您需要以某种动画方式发送通知,则可以使用 jQuery Animation

http://jsbin.com/dadiz/1/edit

您可以在 .click() 函数的帮助下显示它,该函数是 jquery 中的内置函数。

$("the_id").click(function(){
 //your stuff here
});

在此处查找有关.click()的更多信息。