我对PHP非常缺乏经验,而且我在调用mootools函数时遇到了麻烦。
这是我的代码:
echo '<script language="JavaScript">';
echo "Sexy.error('Test!');";
echo '</script>';
查看源代码时如下所示:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Bath Solutions</title>
<link xmlns="" href="html_includes/css/main.css?version=10.03.05" rel="stylesheet" type="text/css" media="all" />
<link xmlns="" href="html_includes/mootools/Autocompleter.css?version=10.03.05" rel="stylesheet" type="text/css" media="screen" />
<link xmlns="" href="html_includes/css/print.css?version=10.03.05" rel="stylesheet" type="text/css" media="print" /><link xmlns="" href="html_includes/css/schedule.css?version=10.03.05" rel="stylesheet" type="text/css" media="all" />
<script language="javascript" type="text/javascript" src="html_includes/mootools.js?version=10.03.05"></script>
<script language="javascript" type="text/javascript" src="html_includes/main.js.php?version=10.03.05"></script>
<script language="javascript" type="text/javascript" src="html_includes/datepicker.js?version=10.03.05"></script>
<script language="javascript" type="text/javascript" src="html_includes/mootools/Observer.js?version=10.03.05"></script>
<script language="javascript" type="text/javascript" src="html_includes/mootools/Autocompleter.js?version=10.03.05"></script>
<script language="javascript" type="text/javascript" src="html_includes/mootools/Autocompleter.Request.js?version=10.03.05"></script>
<script type="text/javascript" src="html_includes/mootools/sexyalert/sexyalertbox.v1.2.moo.js?version=10.03.05"></script>
<link rel="stylesheet" type="text/css" media="all" href="html_includes/mootools/sexyalert/sexyalertbox.css?version=10.03.05"/>
<script type="text/javascript" src="html_includes/fckeditor/fckeditor.js?version=10.03.05"></script>
</head>
<body>
<script language="JavaScript">Sexy.error('Test!');</script>
...
当我用一个简单的alert('test')
尝试它时效果很好..我很困惑?!?
更新:我尝试在锚标记中调用Sexy.error()
onClick
并且工作正常:
<a href="#" onclick="Sexy.error('test');return false;">click to test</a>
答案 0 :(得分:1)
将电话打包成domready
<script type="text/javascript">
window.addEvent("domready", function() {
Sexy.error('test');
});
</script>
如果类依赖于dom的任何部分,例如<div id='sexy'></div>
为'there',它将无法正常工作 - 在运行脚本块时,目标div不会可用于DOM操作。
答案 1 :(得分:0)
您尚未指定您的mootools版本,但根据this,没有error
方法。尝试将代码更改为:
echo '<script language="JavaScript">';
echo "Sexy.alert('Test!');";
echo '</script>';
代替。
并记得将此添加到您的HTML中:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/mootools/1.2.1/mootools-yui-compressed.js"></script>
<script type="text/javascript" src="sexyalertbox.v1.2.moo.js"></script>
<link rel="stylesheet" type="text/css" media="all" href="sexyalertbox.css"/>
答案 2 :(得分:0)
您必须学习如何使用FireBug - 在这种情况下将极大地帮助您。