douduan2272 2013-09-06 23:30
浏览 35

我有一个.php文件,我的外部css或javascript都没有工作

I am quite new to PHP.

I built a .php website which I've hooked up to a local test server using MAMP. For some reason, although I can view the site in my browser (Chrome), and the PHP works (I built a form that sends email), none of the CSS from the external style sheet I linked, nor the javascript from the external javascript file I linked is working.

If I type any of the CSS or script inline, everything works fine. I've used external files many times before in .html files and they have all worked just fine. What am I doing wrong here?

my .php file:

<?php

$to = 'email@email.com';
$subject = 'subject';
$message = $_POST['message'];

$message = <<<EMAIL

$message

EMAIL;

$header = '$email';

if($_POST){

    mail($to, $subject, $message);

}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Php Test</title>
</head>
<link rel="stylesheet" type="text/css" href="PhpTest.css"/>


<body onload="alertFunction()">

<h1 id="header">Text text text.</h1>

<form action="?" method="post">

<ul>
    <li>
<label for="message">Message:</label>
<textarea id="message" name="message" cols="42" rows="9"></textarea>
</li>
<li>
<input type="submit"  value="Submit"</li>
</li>
</ul>

</form>

<footer>
<script type="text/javascript" src="PhpTest.js"></script>
</footer>
</body>
</html>

my css:

#header{
    color:#3C9;
}

my javascript:

function alertFunction()
{
alert("Alert.");
}

Update: I started a new .php in Dreamweaver from scratch. I added no actual PHP code; I just placed a header within the body, linked to an external CSS within the head tag (within the CSS I simply designated the header's color as a blue) and tried that. As it turns out, Dreamweaver will recognize the link and apply the CSS it when I view the site using the design/split screen, however when I try to preview it in Chrome, it fails. I have no idea what this means, but if anyone has any theories they would be very much appreciated. Thanks.

  • 写回答

5条回答 默认 最新

  • doumi1944 2013-09-06 23:33
    关注

    Try putting the full url for the location of css and javascript like:

    href="http://www.domain.com/css_file.css"
    
    评论

报告相同问题?

悬赏问题

  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗