[英]How call jquery function inside php code - $ is not defined
I want to use jQuery-confirm dialog instead of echoing a Javascript alert
from PHP. 我想使用jQuery确认对话框,而不是从PHP回显Javascript
alert
。 When I run following code it shows me this error: 当我运行以下代码时,它向我显示此错误:
$ is not defined
$未定义
echo "<script>$.alert({title: 'Alert!',content: 'Simple alert!',});</script>";
Be sure to include the jQuery library first. 确保首先包含jQuery库。
Then, if it still do not work, like you say in comments, try wrapping your alert inside a $(document).ready()
: 然后,如果它仍然不起作用,如您在评论中所说,请尝试将警报包装在
$(document).ready()
:
echo "<script>$(document).ready(function(){$.alert({title: 'Alert!',content: 'Simple alert!'});});</script>";
您必须了解Javascript在客户端(浏览器)上运行,并尝试将其输出到html页面,同时包括用于Jquery-confirm的脚本源,您将看到$ .alert开始工作。
您想确认是否已链接jQuery库...,也可以将代码放在包含的jQuery库之后...
Endless thanks to all. 无休止的感谢大家。 I have solved my problem with moving script libraries to my header section.
我已经解决了将脚本库移到标头部分的问题。 And it works now ;)
它现在有效;)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.