Materializecss Toasts with PHP
Materializecss Toasts with PHP
所以我正在制作这个web控制面板,但我不擅长JS
。我使用MaterializeCSS
+ HTML
+ PHP
作为DB
登录,等等。
我想有以下简单的功能,但由于某种原因,我失败了。
我想在表格中填写用户名和密码,然后点击登录。因为我不确定Toasts
是如何工作的,我想一旦我切换页面,Toast
实际上就消失了,所以也许最好在打开的新帐户页面中显示toast,而不是登录页面本身。我都试过了,但是没有出现
代码显示Toast:
echo "<script> Materialize.toast('Login successful!', 3000, 'rounded') </script>";
我在俄语的某个地方发现了一个话题,说DOM
有问题,并使用了它的解决方案,但没有成功。
注意:我已经使用了其他依赖js的组件,如Modals
和Tooltips
。
控制台错误: Uncaught ReferenceError: Materialize is not defined
我有两个问题。最重要的是,我是在IF中测试代码,而IF甚至没有被执行。愚蠢的我。其次,我没有使用onDocumentReady - $(function(){});
文档参考器只是检查哪个页面发送我那里,但这里是我的工作代码创建一个MaterializeCSS Toast
从PHP:
echo "
<script>
$(function(){
if (document.referrer == 'http://yourdomain/index.php?p=Login'){
Materialize.toast('Login successful', 2200, 'rounded')
}
});
</script>";
我的一个PHP脚本也有同样的问题。最后,经过大量的研究,我发现我没有包括JQuery。Materialize CSS需要在Materialize .js文件之前加载JQuery。确保jquery已经加载。控制台错误显示,因为JQuery没有加载。
我在我的本地主机上测试了这段代码,没有jquery toast不工作,但加载时它工作得很好。
<?php
if (isset($_GET['msg'])){
$msg = $_GET['msg'];
echo "<script>Materialize.toast('$msg', 3000, 'rounded');</script>";
}
?>
你可以在PHP中像这样设置if条件
<?php
`if (document.referrer == 'http://yourdomain/index.php?p=Login')
{
echo "
<script>
Materialize.toast('Login successful', 2200, 'rounded');
</script>";
}`
?>
相关文章:
- timeago.js with datatable and PHP
- PHP $_GET with jQuery $.get call
- PHP Error with Javascript
- JavaScript with PHP SESSION
- Ajax Call with Post in PHP
- chartJs with MySQL and PHP
- HTML用PHP替换with函数
- InnerHTML with PHP
- Ajax call VERY SLOW with PHP
- jQuery load with php in it?
- Wordpress: POST to .php with Ajax
- Javascript array to PHP with json.stringify
- Call PHP with JavaScript
- js/php with include files
- Javascript array to php with jQuery ajax
- PHP with Javascript - What is the scope of PHP variables ins
- PHP with javascript
- Using TeeChart PHP with javascript
- GET id from php with javascript
- Javascript value to PHP with Jquery