如何使用jQuery发出警报 [英] How to alert using jQuery

查看:97
本文介绍了如何使用jQuery发出警报的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这有效:

$('.overdue').addClass('alert');

但这不是:

$('.overdue').alert('Your book is overdue.'); 

正确的jQuery语法是什么:

What is the correct jQuery syntax for:

FOR EACH CLASS="overdue"
   alert('Your book is overdue');
NEXT

推荐答案

$(".overdue").each( function() {
    alert("Your book is overdue.");
});

请注意,.addClass()"之所以有效,是因为addClass是在jQuery对象上定义的函数.您不能只是将任何旧函数放在选择器的末尾并期望它起作用.

Note that ".addClass()" works because addClass is a function defined on the jQuery object. You can't just plop any old function on the end of a selector and expect it to work.

另外,用n个弹出窗口轰击用户(其中​​n =过期的书数)可能不是一个好主意.

Also, probably a bad idea to bombard the user with n popups (where n = the number of books overdue).

也许使用size函数:

Perhaps use the size function:

alert( "You have " + $(".overdue").size() + " books overdue." );

这篇关于如何使用jQuery发出警报的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆