dongmeiran609914 2009-12-04 15:11
浏览 59
已采纳

PHP页面中的JavaScript函数导致PHP选项卡格式出现问题

I am trying to reference a JavaScript file, containing a table sort function, in a PHP file. Everything functions the way it should, but once I add the code below to my PHP report page it causes issues with the format of the tabs on my navigation page. The same issue comes up if I add a random document.write outside of the PHP code. Not a huge issue but rather unsightly to the user.

Is there a better way to reference the JavaScript source doc that will not interfer with my php navigation page format? I feel like there is a simple fix that I am not grasping.

<script language="JavaScript" src="include/sorttable.js"></script>

Also used an the PHP echo inside the PHP tags to make the call, same issue.

Here is part of the navigation code for the tabs that the format issue is coming up on.

<?php

//////////////////////////////////////////////////////////////////////////////////////////////////
function start_page_printer_friendly(
      $section = "home",
      $headContents = null,
      $bodyAttributes = null
)
//////////////////////////////////////////////////////////////////////////////////////////////////

{?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title><?php print $page_title; ?></title>
<link href="/trellis_portal/include/portal.css" media="screen"
   rel="Stylesheet" type="text/css" />
      <?php if ( ! is_null($headContents)) { print $headContents; } ?>
   </head>

<body onload="printpage();" <?php if ( ! is_null($bodyAttributes)) { print $bodyAttributes; } ?>>
   <script language="JavaScript">
      <!--
         function printpage() { window.print(); }
      -->
   </script>
<br />
<?php                     
}

//////////////////////////////////////////////////////////////////////////////////////////////////
function start_page( $section = "home",
                     $subsection = null,
                     $headContents = null,
                     $bodyAttributes = null
                   )
//////////////////////////////////////////////////////////////////////////////////////////////////
{   
    if (isset($_GET['printer']))
    {
        start_page_printer_friendly();
        return;
    }
   $section = strtolower($section);

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title><?php print $page_title; ?></title>

 <?php if ( ! is_null($headContents)) { print $headContents; } ?>
   </head>

<body class=" yui-skin-sam" <?php if ( ! is_null($bodyAttributes)) { print $bodyAttributes; } ?>>
<br />


<div id="header">
<ul>
<!-- 
   <li><a class="<?php print tabSelector($section, 'executive'); ?>"
      href="/trellis_portal/portal.php?section=executive&title=Executive">Executive</a></li>
   <li><a
      class="<?php print tabSelector($section, 'community'); ?>"
      href="/trellis_portal/portal.php?section=community&title=Community">Community</a></li>
-->   
   <li><a class="<?php print tabSelector($section, 'trellis'); ?>"
      href="/trellis_portal/portal.php?section=trellis&title=Trellis">Trellis</a></li>
<!-- 
  • 写回答

3条回答 默认 最新

  • dongzhonggua4229 2009-12-04 15:40
    关注

    I still don't get what you expect but one thing I can see already: EVERYTHING outside is literally transposed, thus

    ?>
    <!DOCTYPE...
    

    will introduce an extra whitespace (newline) at the start before DOCTYPE.

    Also the ending of the script ( --> ) will generate JS syntax error. It is valid HTML but must be commented out ( //--> ) in JS.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序
  • ¥15 onvif+openssl,vs2022编译openssl64
  • ¥15 iOS 自定义输入法-第三方输入法
  • ¥15 很想要一个很好的答案或提示
  • ¥15 扫描项目中发现AndroidOS.Agent、Android/SmsThief.LI!tr
  • ¥15 怀疑手机被监控,请问怎么解决和防止
  • ¥15 Qt下使用tcp获取数据的详细操作
  • ¥15 idea右下角设置编码是灰色的
  • ¥15 全志H618ROM新增分区