我的drupal主体的代码有php代码Text Format:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
<img id="thisImg" alt="img" src="http://localhost/fastcat.com.ph/sites/all/themes/impact_theme/images/ads1.jpg"/>
<script type="text/javascript">
var myImage = new Array();
ctr = 0;
$(function(){
<?php
$log_directory = 'http://localhost/fastcat.com.ph/sites/all/themes/impact_theme/images/images/large/';
foreach(glob($log_directory.'{*.gif,*.jpg,*.png,*.JPG,*GIF,*.PNG}',GLOB_BRACE) as $filename) {
?>
myImage.push("<?php echo $filename?>");
ctr =ctr +1;
<?php
}
?>
<?php
$log_directory2 = 'http://localhost/fastcat.com.ph/sites/all/themes/impact_theme/images/images/large/gallery2/';
foreach(glob($log_directory2.'{*.gif,*.jpg,*.png,*.JPG,*GIF,*.PNG}',GLOB_BRACE) as $filename) {
?>
myImage.push("<?php echo $filename?>");
ctr =ctr +1;
<?php
}
?>
<?php
$log_directory3 = 'http://localhost/fastcat.com.ph/sites/all/themes/impact_theme/images/images/large/gallery3/';
foreach(glob($log_directory3.'{*.gif,*.jpg,*.png,*.JPG,*GIF,*.PNG}',GLOB_BRACE) as $filename) {
?>
myImage.push("<?php echo $filename?>");
ctr =ctr +1;
<?php
}
?>
<?php
$log_directory4 = 'http://localhost/fastcat.com.ph/sites/all/themes/impact_theme/images/images/large/gallery4/';
foreach(glob($log_directory4.'{*.gif,*.jpg,*.png,*.JPG,*GIF,*.PNG}',GLOB_BRACE) as $filename) {
?>
myImage.push("<?php echo $filename?>");
ctr =ctr +1;
<?php
}
?>
<?php
$log_directory5 = 'http://localhost/fastcat.com.ph/sites/all/themes/impact_theme/images/images/large/gallery5/';
foreach(glob($log_directory5.'{*.gif,*.jpg,*.png,*.JPG,*GIF,*.PNG}',GLOB_BRACE) as $filename) {
?>
myImage.push("<?php echo $filename?>");
ctr =ctr +1;
<?php
}
?>
<?php
$log_directory6 = 'http://localhost/fastcat.com.ph/sites/all/themes/impact_theme/images/images/large/gallery6/';
foreach(glob($log_directory6.'{*.gif,*.jpg,*.png,*.JPG,*GIF,*.PNG}',GLOB_BRACE) as $filename) {
?>
myImage.push("<?php echo $filename?>");
ctr =ctr +1;
<?php
}
?>
<?php
$log_directory7 = 'http://localhost/fastcat.com.ph/sites/all/themes/impact_theme/images/images/large/gallery7/';
foreach(glob($log_directory7.'{*.gif,*.jpg,*.png,*.JPG,*GIF,*.PNG}',GLOB_BRACE) as $filename) {
?>
myImage.push("<?php echo $filename?>");
ctr =ctr +1;
<?php
}
?>
<?php
$log_directory8 = 'http://localhost/fastcat.com.ph/sites/all/themes/impact_theme/images/images/large/gallery8/';
foreach(glob($log_directory8.'{*.gif,*.jpg,*.png,*.JPG,*GIF,*.PNG}',GLOB_BRACE) as $filename) {
?>
myImage.push("<?php echo $filename?>");
ctr =ctr +1;
<?php
}
?>
console.log(myImage);
var thisId=0;
window.setInterval(function(){
$('#thisImg').attr('src',myImage[thisId]);
thisId++; //increment data array id
if (thisId==ctr) thisId=0; //repeat from start
},2000);
});
</script>
当我尝试单独在php文件中运行此代码时。
/var/www/unplay/trytoplay.php
它工作正常。 但是当我尝试在drupal身体中写它。它确实有效。 然后我尝试运行我的控制台,它说:
Uncaught TypeError: Object [object Object] has no method 'tinyNav' main-menu.jsmxywgd:85
Uncaught TypeError: Object [object Object] has no method 'cycle'
我尝试安装tinyNav但没有任何事情发生。 谢谢你的帮助。
答案 0 :(得分:1)
尝试更新你的jquery。你可以参考这个链接https://drupal.org/project/jquery_update
我试着没有jquery。
<img id="thisImg" alt="img" src="../fastcat.com.ph/sites/all/themes/impact_theme/images/ads1.jpg"/>
<script type="text/javascript">
var dataArray=new Array();
dataArray[0]="images/img1.png";
dataArray[1]="images/img2.png";
dataArray[2]="images/img3.png";
dataArray[3]="images/img0.png";
var myImage = new Array();
ctr = 0;
<?php
$log_directory = '../fastcat.com.ph/sites/all/themes/impact_theme/images/images/large/';
foreach(glob($log_directory.'{*.gif,*.jpg,*.png,*.JPG,*GIF,*.PNG}',GLOB_BRACE) as $filename) {
?>
myImage[ctr] = "<?php echo $filename?>";
ctr =ctr +1;
<?php
}
?>
<?php
$log_directory2 = '../fastcat.com.ph/sites/all/themes/impact_theme/images/images/large/gallery2/';
foreach(glob($log_directory2.'{*.gif,*.jpg,*.png,*.JPG,*GIF,*.PNG}',GLOB_BRACE) as $filename) {
?>
myImage[ctr] = "<?php echo $filename?>";
ctr =ctr +1;
<?php
}
?>
<?php
$log_directory3 = '../fastcat.com.ph/sites/all/themes/impact_theme/images/images/large/gallery3/';
foreach(glob($log_directory3.'{*.gif,*.jpg,*.png,*.JPG,*GIF,*.PNG}',GLOB_BRACE) as $filename) {
?>
myImage[ctr] = "<?php echo $filename?>";
ctr =ctr +1;
<?php
}
?>
<?php
$log_directory4 = '../fastcat.com.ph/sites/all/themes/impact_theme/images/images/large/gallery4/';
foreach(glob($log_directory4.'{*.gif,*.jpg,*.png,*.JPG,*GIF,*.PNG}',GLOB_BRACE) as $filename) {
?>
myImage[ctr] = "<?php echo $filename?>";
ctr =ctr +1;
<?php
}
?>
<?php
$log_directory5 = '../fastcat.com.ph/sites/all/themes/impact_theme/images/images/large/gallery5/';
foreach(glob($log_directory5.'{*.gif,*.jpg,*.png,*.JPG,*GIF,*.PNG}',GLOB_BRACE) as $filename) {
?>
myImage[ctr] = "<?php echo $filename?>";
ctr =ctr +1;
<?php
}
?>
<?php
$log_directory6 = '../fastcat.com.ph/sites/all/themes/impact_theme/images/images/large/gallery6/';
foreach(glob($log_directory6.'{*.gif,*.jpg,*.png,*.JPG,*GIF,*.PNG}',GLOB_BRACE) as $filename) {
?>
myImage[ctr] = "<?php echo $filename?>";
ctr =ctr +1;
<?php
}
?>
<?php
$log_directory7 = '../fastcat.com.ph/sites/all/themes/impact_theme/images/images/large/gallery7/';
foreach(glob($log_directory7.'{*.gif,*.jpg,*.png,*.JPG,*GIF,*.PNG}',GLOB_BRACE) as $filename) {
?>
myImage[ctr] = "<?php echo $filename?>";
ctr =ctr +1;
<?php
}
?>
<?php
$log_directory8 = '../fastcat.com.ph/sites/all/themes/impact_theme/images/images/large/gallery8/';
foreach(glob($log_directory8.'{*.gif,*.jpg,*.png,*.JPG,*GIF,*.PNG}',GLOB_BRACE) as $filename) {
?>
myImage[ctr] = "<?php echo $filename?>";
ctr =ctr +1;
<?php
}
?>
var thisId=0;
setInterval(function(){
document.getElementById("thisImg").src=myImage[thisId];
// document.write(myImage[thisId]);
thisId++; //increment data array id
if (thisId==ctr) thisId=0; //repeat from start
},2000);
</script>