用于显示错误、警告或通知消息的核心 javascript 函数? [英] Core javascript functions to make error, warning or notice messages appear?

查看:25
本文介绍了用于显示错误、警告或通知消息的核心 javascript 函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道强制错误消息的核心drupal javascript函数是什么?更重要的是,它必须与 Message Effects 一起使用(http://drupal.org/project/messagefx).

Does anyone know what the core drupal javascript functions are to force an error message? More importantly, it must work with Message Effects (http://drupal.org/project/messagefx).

使用 JS 主题,您可以调用这些:(这是 javascript 代码)

With JS Theming you can call these: (this is javascript code)

Drupal.messages.set("The Message!", 'error');

但是,它不挂钩到消息效果中,并且在禁用 JS 主题化后,此功能不再起作用.

But, it doesn't hook into Message Effects, and after disabling JS theming, this function no longer works.

推荐答案

您似乎问错了问题.您看到的状态、警告、错误消息不是由 javascript 调用的.相反,它们由 drupal_set_message() 函数生成.它的工作原理是将消息保存在该用户的会话表中,然后在该用户(重新)加载页面时打印它们.它以 page.tpl.php 中的 $messages 结尾.我相信没有此功能的 javascript 版本,但您可以模仿它.这并不比在页面上插入一些 html 更难,比如.

It seems like you have asked the wrong question. The status, warning, error messages that you see, is not invoked by javascript. Instead they are generated by the drupal_set_message() function. It work, by saving the messages in the session table for that user, and then they get printed whenever that user (re)load a page. It ends up as $messages in the page.tpl.php. I believe that there are no javascript version of this functionality, but you could mimic it. It's no harder than to insert some html on the page, something like.

$("#message").append('<div class="message error">The error message</div>');

我不确定确切的 html 结构,而且它也因主题而异,但您明白了.如果你采用这种方法,你还需要钩入messagefx模块的js来添加效果,但这应该不会太难.

I'm not sure about the exact html structure, and it cal also vary from theme to theme, but you get the idea. If you do take this approach, you will also need to hook into the messagefx module's js, to add the effect, but this shouldn't be too hard.

这篇关于用于显示错误、警告或通知消息的核心 javascript 函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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