我是 jquery 的新手。我正在使用 Notyfy jQuery 插件。我想在特定条件下显示带有消息的通知栏。想要在特定条件下显示成功和错误消息
我想做这样的事情。请更正我的代码,以便我可以成功实现这个库
var notyfy-success = notyfy({text: 'successfully deleted'});
var notyfy-error = notyfy({text: 'somethings wrong'});
$(document).ready(function(){
if (true){
alert("hello");
notyfy-success.show('success bar ');
}else{
notyfy-error.show('error bar ');
}
});
最佳答案
如果您在 if() 条件中使用 TRUE,则永远不会执行 else 脚本。 (买我想你知道)。然而...
我看到了插件的文档,你不需要实例化 notyfy-success
和 notyfy-error
只定义它们(TAKE CARE 字符 -
在变量名中不是一个好主意,使用 _
),然后在“if”语句中实例化它们:
var _delete = true, //is the returned value of a action that delate somethig set to "false" and try
notyfy_success, notyfy_error;
$(document).ready(function(){
if (_delete){
notyfy_success = notyfy({text: 'successfully deleted'});
}else{
notyfy_error = notyfy({text: 'somethings wrong'});
}
});
现在,在文档准备就绪时,将显示 notyfy_success 通知,如果您将 _delete
设置为 false
notyfy_error 将改为显示 notyfy_success。
http://jsfiddle.net/Frogmouth/43C7Q/
天啊……我的英语很糟糕……我很抱歉。我希望你能理解..我的不好。
关于jquery 显示和隐藏通知 - 通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21406747/