如何将Notify.js与按钮一起使用

How to use Notify.js with button?

本文关键字:按钮 一起 js Notify      更新时间:2023-09-26

我下载了Notify.js的文件,并将它们放在网页的根目录中。我试着测试它,但点击按钮时没有得到任何东西

<html>
<head>
<title>Untitled</title>
<script src="notify.js"></script>
</head>
<body>
<input name="notif" type="button" value="Shoow notif" onclick="$(".elem-demo").notify("Hello Box");">
</body>
</html>

怎么了?

这是你的答案和工作:

<html>
<head>
<title>Untitled</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="notify.js"></script>
</head>
<body>
<input name="notif" type="button" value="Shoow notif" onclick="$('.elem-demo').notify('Hello Box');"/>
<div class="elem-demo">a Box</div>
</body>
</html>

1-您忘记在文件中包含jquery。

2-您应该创建一个具有elem-demo类的元素

3-您的javascript出现问题!你不能使用双引号,它的子项也有双引号。

这是你的代码示例,然后是我的代码:

onclick="$(".elem-demo").notify("Hello Box");"  //Your code
onclick="$('.elem-demo').notify('Hello Box');"  //My code