jquery 编写不显眼的 javascript 帮助
我在 jquery 中有以下代码。
$(function() {
$('.test').click(function() {
alert('this is a test');
});
});
我意识到这并不引人注目,但我想尝试通过做这样的事情来使其更加不引人注目。
$(function() {
$('.test').submitAlert();
*and place the alert message right here.
});
然后我就可以在不同的类上调用警报消息,而无需重新输入代码。有人可以告诉我如何用 jquery 向我执行此操作吗?
I have the following code in jquery.
$(function() {
$('.test').click(function() {
alert('this is a test');
});
});
I realize that this is unobtrusive, but I would like to try and make it even more unobtrusive by doing something like this.
$(function() {
$('.test').submitAlert();
*and place the alert message right here.
});
Then I would be able to call the alert message on different classes without having to retype the code. Could somebody please show how to do this to me with jquery please?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将代码包装到插件中:
用法:
这是一个工作示例: http://jsfiddle.net/安德鲁惠特克/UGsHR/1/
You could wrap your code into a plugin:
Usage:
Here's a working example: http://jsfiddle.net/andrewwhitaker/UGsHR/1/