[英]Drupal Jquery didn't work in body content
我為我的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,但沒有任何反應。 謝謝您的幫助。
嘗試更新您的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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.