如何在html中设置文本脚本的样式?

时间:2017-06-04 19:27:31

标签: javascript php html css

我有一个hits.php文件,它将$x变量传递到我的index.php文件中,该文件是我网站的hitcounter。我在hits.php和index.php中尝试了很多css样式但是没有一个能够工作!有人会告诉我如何在index.php中设置我的php输出样式吗?

Hits.php:

           <?php
              $counts = ("counter.txt");
              $hits = file($counts);
              $hits[0] ++;
              $fp = fopen($counts, "w");
              fputs($fp , "$hits[0]");
              fclose($fp);
              $x=$hits[0];
              header("Content-type: text/javascript");
              echo "document.write('" . $x . "');";
              ?>

的index.php:

              <script type="text/javascript" src="hits.php"></script>

1 个答案:

答案 0 :(得分:1)

我试过这个并且有效!

首先,我不需要变量.$x.因此我将使用.$hits[0].代替。所以代码就像:

      <?php     
          echo '<span class="counter">'.$hits[0].'</span>'; 
      ?>       
        <style type="text/css">
            .counter{
                font-size: 50px;
                color: #ff4d4d;
            }
        </style>