<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
<script>
function page_choose(num)
{
alert ("aa");
alert (aa[num]);
}
</script>
</head><body>
<script>
aa= new Array();
aa[0]=111;  //这样写
page_choose(0);
</script>
</body>
</html>

解决方案 »

  1.   

    <div>
    <?php
    include ("add_nav.htm");
    ?><script language="javascript">
    function page_choose(num)
    {
    alert (tmp_2[num]);
    window.document.forms["trade_page"].query_id.value=num;
    window.document.forms["trade_page"].answer_id.value=num;
    alert (window.document.forms["trade_page"].answer_id.value);
    }
    </script><form enctype="multipart/form-data" action="./index.asp?trade" method="POST" name="trade_page">
    <input type="hidden" name="query_id" value="unknown">
    <input type="hidden" name="answer_id" value="unknown">
    </form><td width="559" height="500" bgcolor="#FFFFFF" valign="top">
    <div class="content_box" style="text-indent:0px;width:520px;"><!-- content_box began -->
    <div class="text_content" style="top:0px;position:relative;">上海林木展览制作工厂:内部竟价平台</div>
    <div class="text_orange_title" style="top:15px;position:relative;">欢迎您光临!</div>
    <script language="JavaScript">
    <!--
    today_date();
    // -->
    </script>
    <table cellpadding="0" cellspacing="0" width="510" border="0" bgcolor="#EEEEEE" style="top:15px;position:relative;background-repeat:repeat-x;">
    <tr><td align="justify"><div class="text_content"><b>招标:</b></div></td>
    <td align="center"><div class="text_content"><b>创建日期:</b></div></td>
    <td align="center"><div class="text_content"><b>截止日期:</b></div></td>
    <td align="center"><div class="text_content"><b>最后回复:</b></div></td></tr>
    <?php
    $db=mysql_connect("localhost","root","")
            or die("连接数据库失败");
    mysql_select_db("linmu",$db);
    $query="SELECT query_id,query_title,answer_id,establish_time,death_line FROM queries";
    $result=mysql_query($query,$db)
              or die("Error_Number: 0002,database query failed");
    $i=0;
    while ($row=mysql_fetch_array($result))
    {
    echo '<tr><td><div class="text_content"><a href="./index.asp?trade" onClick="page_choose(tmp_2['.$i.']);">'.$row["query_title"].'</a></div></td>';
    echo '<td><div class="text_content">'.substr($row["establish_time"],0,4).'-'.substr($row["establish_time"],4,2).'-'.substr($row["establish_time"],6,2).'</div></td>';
    echo '<td><div class="text_content">'.substr($row["death_line"],0,4).'-'.substr($row["death_line"],4,2).'-'.substr($row["death_line"],6,2).'</div></td>';
    echo '<td><div class="text_content">'.substr($row["death_line"],0,4).'-'.substr($row["death_line"],4,2).'-'.substr($row["death_line"],6,2).'&nbsp;&nbsp;by&nbsp;&nbsp;</div></td></tr>';
    echo '<script language="javascript">';
    echo 'tmp_1=new Array();';
    echo 'tmp_2=new Array();';
    echo 'tmp_1['.$i.']='.$row["query_id"].';';
    echo 'tmp_2['.$i.']='.$row["answer_id"].';';
    echo 'alert (tmp_2['.$i.']);';
    echo '</script>';
    $i++;
    }
    echo '</table>';
    ?><?php
    /*
    <table cellpadding="0" cellspacing="0" width="510" border="0" bgcolor="#EAFBE9" background="./images/background_trade_tablet.gif" style="top:15px;position:relative;background-repeat:repeat-x;">
    <tr><td><div class="trade_table_title"><div class="text_content"><b>招标:</b>&nbsp;上海九城游戏著作有先公司的站台<br><br></div></div></td></tr>
    </table>
    <table cellpadding="0" cellspacing="0" width="510" border="0" bgcolor="#F2F2F2" background="./images/background_trade_tablec.gif" style="top:10px;position:relative;background-repeat:repeat-x;">
    <tr><td><div class="trade_table_title"><div class="text_content"><b>招标:</b>&nbsp;上海九城游戏著作有先公司的站台<br><br></div></div></td></tr>
    </table>
    <table cellpadding="0" cellspacing="0" width="510" border="0" bgcolor="#F2F2F2" background="./images/background_trade_tablec.gif" style="top:10px;position:relative;background-repeat:repeat-x;">
    <tr><td><div class="trade_table_title"><div class="text_content"><b>招标:</b>&nbsp;上海九城游戏著作有先公司的站台<br><br></div></div></td></tr>
    </table>
    <table cellpadding="0" cellspacing="0" width="510" border="0" bgcolor="#EAFBE9" background="./images/background_trade_tablet.gif" style="top:10px;position:relative;background-repeat:repeat-x;">
    <tr><td><div class="trade_table_title"><div class="text_content"><b>招标:</b>&nbsp;上海九城游戏著作有先公司的站台<br><br></div></div></td></tr>
    </table>
    <table cellpadding="0" cellspacing="0" width="510" border="0" bgcolor="#EAFBE9" background="./images/background_trade_tablet.gif" style="top:10px;position:relative;background-repeat:repeat-x;">
    <tr><td><div class="trade_table_title"><div class="text_content"><b>招标:</b>&nbsp;上海九城游戏著作有先公司的站台<br><br></div></div></td></tr>
    </table>
    <table cellpadding="0" cellspacing="0" width="510" border="0" bgcolor="#EAFBE9" background="./images/background_trade_tablet.gif" style="top:10px;position:relative;background-repeat:repeat-x;">
    <tr><td><div class="trade_table_title"><div class="text_content"><b>招标:</b>&nbsp;上海九城游戏著作有先公司的站台<br><br></div></div></td></tr>
    </table>
    */
    ?><br><br><br>
    </div><!-- content_box ended -->
    </td>
    </tr>
    </table>
    </div>
      

  2.   

    楼上不知道您看懂了吗?
    第九行的alert (tmp_2[num]);
    出来是undifined
    echo 'alert (tmp_2['.$i.']);';
    在浏览器下出现我要的值,
    但它传不到page_choose(num)里面!
    我在网页上有了page_choose(1)这句话的!
      

  3.   

    简化版:
    <script language="javascript">
    function page_choose(num)
    {
    alert (tmp_1[0]);  //但这里没有!!!!!
    alert (tmp_1[num]);
    }
    </script><td width="559" height="500" bgcolor="#FFFFFF" valign="top">
    <div class="content_box" style="text-indent:0px;width:520px;"><!-- content_box began -->
    <div class="text_content" style="top:0px;position:relative;">上海林木展览制作工厂:内部竟价平台</div>
    <div class="text_orange_title" style="top:15px;position:relative;">欢迎您光临!</div>
    <script language="JavaScript">
    <!--
    today_date();
    // -->
    </script>
    <table cellpadding="0" cellspacing="0" width="510" border="0" bgcolor="#EEEEEE" style="top:15px;position:relative;background-repeat:repeat-x;">
    <tr><td align="justify"><div class="text_content"><b>招标:</b></div></td>
    <td align="center"><div class="text_content"><b>创建日期:</b></div></td>
    <td align="center"><div class="text_content"><b>截止日期:</b></div></td>
    <td align="center"><div class="text_content"><b>最后回复:</b></div></td></tr>
    <?php
    $db=mysql_connect("localhost","root","")
            or die("连接数据库失败");
    mysql_select_db("linmu",$db);
    $query="SELECT query_id,query_title,answer_id,establish_time,death_line FROM queries";
    $result=mysql_query($query,$db)
              or die("Error_Number: 0002,database query failed");
    $i=0;
    while ($row=mysql_fetch_array($result))
    {
    echo '<tr><td><div class="text_content"><a href="./index.asp?trade" onClick="page_choose('.$i.');">'.$row["query_title"].'</a></div></td>';
    echo '<td><div class="text_content">'.substr($row["establish_time"],0,4).'-'.substr($row["establish_time"],4,2).'-'.substr($row["establish_time"],6,2).'</div></td>';
    echo '<td><div class="text_content">'.substr($row["death_line"],0,4).'-'.substr($row["death_line"],4,2).'-'.substr($row["death_line"],6,2).'</div></td>';
    echo '<td><div class="text_content">'.substr($row["death_line"],0,4).'-'.substr($row["death_line"],4,2).'-'.substr($row["death_line"],6,2).'&nbsp;&nbsp;by&nbsp;&nbsp;</div></td></tr>';
    echo '<script language="javascript">';
    echo 'tmp_1=new Array();';
    echo 'tmp_2=new Array();';
    echo 'tmp_1['.$i.']='.$row["query_id"].';';//tmp_1数组被赋值
    echo 'tmp_2['.$i.']='.$row["answer_id"].';';//tmp_1数组被赋值
    echo 'alert (tmp_1['.$i.']);';tmp_1有值,tmp_1[0]为query_id的值!为111111
    echo '</script>';
    $i++;
    }
    echo '</table>';
    ?>
      

  4.   

    aa[]=111;//不对
    应该是aa.push(111);
    或者aa[0]=111;
    ------------------------
    此外根据你后面的代码,你的tmp_1和tmp_2根本不该那么定义,否则你每次循环的时候就冲掉了原来的值,你的意思是应该作为全局变量的,你就应该定义在文档的上层,这样才能保证能访问;否则应为你冲掉了前面的tmp_1和tmp_2数组变量从而冲掉了原来的元素,只保留了最后一次添加的元素,这样在访问前面定义的元素是就出现未定义的情况.
      

  5.   

    echo 'tmp_1=new Array();';
    echo 'tmp_2=new Array();';
    ----------------------------------
    这个不应该在循环中间,而应该提出到外围