我正在将一个 PHP 项目转换为 CakePHP,并且遇到了日期选择器、文本编辑器等预定义 jQuery 脚本的问题。
这是我在页面上添加的 CSS 脚本:(如果您右键单击页面并单击页面源)
<link rel="stylesheet" type="text/css" href="/cakeskite/css/common.css" />
<link rel="stylesheet" type="text/css" href="/cakeskite/css/creatorcommon.css" />
<link rel="stylesheet" type="text/css" href="/cakeskite/css/jquery-ui.css" />
<link rel="stylesheet" type="text/css" href="/cakeskite/css/cssbuttons.css" />
<link rel="stylesheet" type="text/css" href="/cakeskite/css/jquery-te-1.4.0.css" />
<link rel="stylesheet" type="text/css" href="/cakeskite/css/jquery.datepick.css" />
<script type="text/javascript" src="/cakeskite/js/jquery.js"></script>
<script type="text/javascript" src="/cakeskite/js/jquery-ui-1.8.2.custom.min.js"></script>
<script type="text/javascript" src="/cakeskite/js/jquery.simplemodal.js"></script>
<script type="text/javascript" src="/cakeskite/js/jquery.datepick.js"></script>
<script type="text/javascript" src="/cakeskite/js/jquery.ptTimeSelect.js"></script>
<script type="text/javascript" src="/cakeskite/js/jquery-te-1.4.0.js"></script>
<script type="text/javascript" src="/cakeskite/js/common.js"></script>
<script type="text/javascript" src="/cakeskite/js/creatorcommon.js"></script>
如果我单击任何链接,则表明该文件存在,因此不是找不到文件的问题。我也可以在 chrome 控制台中检查
我在布局文件中添加了我的脚本,如下所示:
<?php
echo $this->Html->css('common');
echo $this->Html->css('creatorcommon');
echo $this->Html->css('jquery-ui');
echo $this->Html->css('cssbuttons');
echo $this->Html->css('jquery-te-1.4.0');
echo $this->Html->css('jquery.datepick');
echo $this->Html->script('jquery');
echo $this->Html->script('jquery-ui-1.8.2.custom.min');
echo $this->Html->script('jquery.simplemodal');
echo $this->Html->script('jquery.datepick');
echo $this->Html->script('jquery.ptTimeSelect');
echo $this->Html->script('jquery-te-1.4.0');
echo $this->Html->script('common');
echo $this->Html->script('creatorcommon');
echo $scripts_for_layout;
?>
我将所有 CSS 和脚本文件放在 webroot/js 和 webroot/css 文件夹中
我收到如下错误:
Object [object Object] has no method 'datepick'
而他们在非 cakephp 项目中工作。这是来自 html 和脚本文件的行
注意:我正在使用 ajax 加载内容,并且在收到数据时绑定控件
$.ajax({
url: 'loadtests',
type: 'POST',
data: 'category_id=' + category_id + '&subcategory_id=' + subcategory_id,
success: function(result){
stopLoading();
if(!isSessionExpired(result)){
$(".msg").html(" ");
if(result.indexOf("No tests found...")>-1){
$(".tests").html("No tests found...");
}
else{
$(".tests").html(result);
$(".testfound").css("display","block");
$(".durationrow").css("display","block");
$(".noduration").css("display","none");
disableKeyPress($("input[name='startdate']"));
disableKeyPress($("input[name='enddate']"));
disableKeyPress($("input[name='starttime']"));
disableKeyPress($("input[name='endtime']"));
$("input[name='startdate']").datepick({dateFormat: 'yyyy-mm-dd', changeMonth: false});
$("input[name='enddate']").datepick({dateFormat: 'yyyy-mm-dd', changeMonth: false});
$("input[name='starttime']").ptTimeSelect();
$("input[name='endtime']").ptTimeSelect();
$(".datepicker").css("display","block");
$("select[name='test']").change(
function(){
checkTestDuration();
}
);
checkTestDuration();
}
}
else
notLoggedIn();
}
这是我的html表单:
<div class="createrow timebound testfound">
<div class="column150 leftfloat">Start Date</div>
<div class="column250 leftfloat">
<input name="startdate" class="txt100" />
</div>
<div class="column150 leftfloat msg"> </div>
<div class="clear"></div>
</div>
<div class="createrow timebound testfound">
<div class="column150 leftfloat">End Date</div>
<div class="column250 leftfloat">
<input name="enddate" class="txt100" />
</div>
<div class="column150 leftfloat msg"> </div>
<div class="clear"></div>
</div>
<div class="createrow timebound testfound">
<div class="column150 leftfloat">Start Time</div>
<div class="column250 leftfloat">
<input name="starttime" class="txt100" />
</div>
<div class="column150 leftfloat msg"> </div>
<div class="clear"></div>
</div>
<div class="createrow timebound testfound">
<div class="column150 leftfloat">End Time</div>
<div class="column250 leftfloat">
<input name="endtime" class="txt100" />
</div>
<div class="column150 leftfloat msg"> </div>
<div class="clear"></div>
</div>
我究竟做错了什么?