简体   繁体   English

为什么我的PHP代码不起作用?

[英]Why is my PHP code not working?

I have made a code -- 我已经写了一个代码-

<?php

header("Content-type: text/javascript");
require_once('../php/config.php');
$domail_theme = $_GET['theme'];

?>

<?php
  if($domail_theme=='default')
  {
?>

  $('div.theme_content').mouseover(function () {
    $(this).stop().animate({
      backgroundColor : '#234'
    }, 250, 'linear', function() { });
  });

  $('div.').mouseout(function () {
    $(this).animate({
      backgroundColor : '#ddd'
    }, 400, 'linear', function() { });
  });

<?php
  }
?>

And here is the script including tag -- 这是包含标签的脚本-

<script src="domail_res/scripts/java/settings_form_css.php?theme=default"></script>

The thing I want is that when I mouse over on the div element with class theme_content it's background changes according to the given one in the animate function. 我想要的是,当我将鼠标悬停在带有theme_content类的div元素上时,其背景会根据动画函数中给定的背景而变化。 It is working for the input element but that script is original javascript and in this I have included php that's why I'm thinking whether the php code I used is wrong or my javascript . 它适用于input元素,但该脚本是原始javascript ,因此其中包含了php ,这就是为什么我在考虑使用的php代码错误还是我的javascript Also when I include this code in javascript file it works correctly. 另外,当我将此代码包含在javascript文件中时,它也可以正常工作。 And by the I'm including the script tag in between the body tag, is it wrong? 通过将body标签之间的script标签包括在内,这是错误的吗? Please help me out with this one. 请帮我解决这个问题。

Thanks in advance! 提前致谢!

Try to put it inside script. 尝试将其放在脚本中。 <script></script>

And also it's possible that DOM might not have been loaded. 而且也可能未加载DOM。 so try putting wrappint in $(document).ready(function() { /*Your code here*/}) 因此请尝试将wrappint放入$(document).ready(function() { /*Your code here*/})

And also put alert('hello'); 并且还放置alert('hello'); to check if that code is being executed or not. 检查该代码是否正在执行。 It might be useful in debugging. 在调试中可能很有用。

The most likly explanation is that 'theme" is not set to 'default' in your URL request. 最恰当的解释是您的URL请求中未将“主题”设置为“默认”。

This should be easy to check. 这应该很容易检查。 Also you can "View" -> "Page Source" in your browser and look at the html your php program is actually generating. 您也可以在浏览器中“查看”->“页面源代码”,并查看您的php程序实际生成的html。 If my guess is right you won't see your mouseover function in the page. 如果我的猜测是正确的,那么您将在页面中看不到鼠标悬停功能。

Hi you should write like this:- 嗨,您应该这样写:-

<?php
 if($domail_theme=='default')
{
?>
<script>

$('div.theme_content').mouseover(function () {
$(this).stop().animate({
  backgroundColor : '#234'
}, 250, 'linear', function() { });
});

$('div.').mouseout(function () {
$(this).animate({
  backgroundColor : '#ddd'
}, 400, 'linear', function() { });
});
</script>
<?php
}
?>

Just need add tag between on your php if statement. 只需要在您的php if语句之间添加标签。

Hope can help you. 希望可以帮到您。

如果将type ='text / javascript'添加到脚本标签中,效果会更好吗?

<script type='text/javascript' src="domail_res/scripts/java/settings_form_css.php?theme=default"></script>

Why not just put the php logic in your main file and include the javascript as plain javascript? 为什么不只将php逻辑放在您的主文件中,然后将javascript作为普通javascript包含在内?

<?php
 if($domail_theme=='default')
{
?>
<script type='text/javascript' src="domail_res/scripts/java/settings_form_css.js"></script>
<?php
}
?>

Seems like overcomplicating things 似乎使事情变得过于复杂

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM