<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>外汇兑换</title>
<style type="text/css">
#msg {
line-height: 150px;
text-align: center;
font-size: 230%;
font-family: sans-serif;
}

form, h2{
text-align: center;
}
</style>
</head>

<body>
<h2>外汇兑换</h2>
<hr />
<form action='?check' method="post">
<input type='text' name="quantity" />
<select name="currencyr">
<option value='USD'>美元USD</option>
<option value='HKD'>港元HKD</option>
<option value='EUR'>欧元EUR</option>
<option value='GBP'>英镑GBP</option>
<option value='JPY'>日元JPY</option>
</select>
<button type="submit">兑换</button>
</form>
<div id="msg"></div>
<?php
    //phpinfo();
        if(isset($_REQUEST['check'])){
         define('USD', 6.125);
define('HKD', 0.789);
define('EUR', 7.899);
define('GBP', 9.214);
define('JPY', 0.061);

$quantity=intval($_REQUEST['quantity']);
$currency=$_REQUEST['currency'];

switch($currency)
{
case 'USD':
$amount=$quantity*USD;
break;
case 'HKD':
$amount=$quantity*HKD;
break;
case 'EUR':
$amount=$quantity*EUR;
break;
case 'GBP':
$amount=$quantity*GBP;
break;
case 'JPY':
$amount=$quantity*JPY;
break;
}

                        //主要是下面这段有问题
echo '<script language="javascript">'.
     'document.getElementById("msg").innerHTML="'.
     $quantity.' '.$currency.' = '.$amount.' RMB";'.
     '</script>';
        }
        ?>
</body>
</html>不出意外应该是如下但是我的电脑出现了这个情况哪位明白这是出什么问题了?谢谢

解决方案 »

  1.   

    你把这段代码全部改成js吧
    你现在的代码是一半js,一半php,注意:js是不能直接使用PHP变量的
      

  2.   

    上边的代码是从一个PHP教学视频里得到的,其视频里边可以正常显示,但是我自己的电脑上却不行,我想代码应该没问题,是其他方面的问题
      

  3.   

    我是用aptana编辑的,会不会与这个软件有什么关系
      

  4.   

    你不是按 php 运行的