>实际上我正在做zendframework-2.0.3。 根据 zendframework-ZendSkeletonApplication-zf-release-2.0.3-0-g657a752 我添加了所有脚本,但.ready()
不起作用。 在我的视图页面中,我只添加了此代码
<script>
$(document).ready(function(){
alert('ok');
});
</script>
但它不起作用,但 .click() 和其他函数可以工作。 这是我在布局中添加脚本的方式 headTitle('ZF2 '. $this->translate('Skeleton Application'))->setSeparator(' - ')->setAutoEscape(false) ?>
<?php echo $this->headMeta()->appendName('viewport', 'width=device-width, initial-scale=1.0') ?>
<!-- Le styles -->
<?php echo $this->headLink(array('rel' => 'shortcut icon', 'type' => 'image/vnd.microsoft.icon', 'href' => $this->basePath() . '/images/favicon.ico'))
->prependStylesheet($this->basePath() . '/css/foundation.min.css')
->prependStylesheet($this->basePath() . '/css/foundation.css')
->prependStylesheet($this->basePath() . '/css/app.css')
?>
<!-- Scripts -->
<?php echo $this->headScript()->prependFile($this->basePath() . '/js/html5.js', 'text/javascript', array('conditional' => 'lt IE 9',))
->prependFile($this->basePath() . '/js/bootstrap.min.js')
->prependFile($this->basePath() . '/js/app.js', 'text/javascript')
->prependFile($this->basePath() . '/js/jquery.foundation.orbit.js', 'text/javascript')
->prependFile($this->basePath() . '/js/jquery.js', 'text/javascript')
->prependFile($this->basePath() . '/js/validation.js', 'text/javascript')
->prependFile($this->basePath() . '/js/jquery.foundation.alerts.js', 'text/javascript')
->prependFile($this->basePath() . '/js/jquery.foundation.forms.js', 'text/javascript')
->prependFile($this->basePath() . '/js/jquery.foundation.buttons.js', 'text/javascript')
->prependFile($this->basePath() . '/js/date.js', 'text/javascript')
?>
</head>
请帮助我
嗯,尝试
<script type="text/javascript">
$(document).ready(function(){
alert('ok');
});
</script>
更新
哦,我看到你有错误的结束标签
您正在使用
<script>
将其更改为
</script>
我在 2.0.3 中发现的是,如果您的文档中有body onload=
,则不会运行ready
函数。 它在 1.4.2 版中运行。
我只是遇到了同样的问题,原因是我在布局底部加载了 headScript 文件,并且视图中的脚本没有在文档准备就绪时触发。
解决方案是在布局的 head 部分中加载 jQuery。
在 php.
中遇到同样的问题而不是
<script type="text/javascript" src="Scripts/jquery.js" />
我将其更改为
<script type="text/javascript" src="Scripts/jquery.js"></script>
此方法已被弃用。
用:
$(function() {
// code that will be executed on DOM ready
});