解决方案 »

  1.   

    php 运行于服务端,不能主动地获取客户端的任何信息
    一切可被 php 见到的客户端信息,都是客户端发送的
      

  2.   

    谁输入这个值?哪个CPU执行方法计算?
    如果是用户(客户端)输入,服务器的CPU计算,那要有一个传输过程(提交)
    客户端不能执行php的,或者说到了客户端就不是一个php了,只是html
      

  3.   

    您的意思是不是:在同一php页面上,php不能获得本页面上元素的值。php方法要想使用页面元素的值只能通过页面提交的方式?
    我这个php方法是通过页面上输入框的值动态生成datagrid的列的。 这样的情况该怎么解决参数传递的问题?
      

  4.   

    php页面不能获得本页面的元素值?可以不可以通过js或者jquery让php方法能获得本页面元素的值?
      

  5.   

    你需要自己写 js 程序实现
    当然你可以使用 jquery 框架,他众多的插件足以满足应用需求
      

  6.   

    是要把function initRows1($bym,$eym){
    ......    
    }这个方法实现的供全部用js代码重新写,还是用js或者jquery获得页面元素的值传递到方法中?
      

  7.   

    斑竹请教下:我用js获取了值传递给这个方法,发现同样的参数输出却不正确
    <?php
    $btime= "<script>document.write(betime)</script>";
    $etime="<script>document.write(endtime)</script>";
    //echo $btime."***--".$etime;//输出 '2013-12'***'2014-02' 
    initRows1($btime, $etime);//同样的参数输出却不正确
    //initRows1('2013-12', '2014-02');//initRows1方法正确输出
    ?>
    方法代码
    function initRows1($bym,$eym){
    //echo $bym."^^^^^".$eym."<br>";
    //判断两个日期间相差多少月
    $bym_list=explode("-",$bym);
    $eym_list=explode("-",$eym);
    if($bym_list[0]==$eym_list[0]){
    $months=abs($bym_list[1]-$eym_list[1]);
    }else{
    $months=abs(($eym_list[0]-$bym_list[0]-1)*12)+abs($eym_list[1]+(12-$bym_list[1]));
    }
    echo $bym."^---^".$eym."<br>";
    $items=array();
    for ($i=0;$i<=$months;$i++){
    echo "xxxx ".$i."--".date("Y-m",strtotime("+$i months",strtotime($bym)))."****".$bym."<br>";
    //echo substr(getMonth(date("Y-m",strtotime("+$i months",strtotime($bym)))),-4)."---";
    echo "<th colspan='3'><strong>".substr(getMonth(date("Y-m",strtotime("+$i months",strtotime($bym)))),-4).substr(getMonth(date("Y-m",strtotime("+$i months",strtotime($bym)))),0,-4)."</strong></th>";
    }}
    页面输出关键是这一句
    echo "xxxx ".$i."--".date("Y-m",strtotime("+$i months",strtotime($bym)))."****".$bym."<br>";
    其中$bym明明是2013-12但是date("Y-m",strtotime("+$i months",strtotime($bym)))输出却是1970-01。怎么回事?
      

  8.   

    2013-12 不是完整的日期表示
    需 strtotime($bym .'01') 才可以date("Y-m",strtotime("+$i months",strtotime($bym)))
    写作
    date("Y-m", strtotime("+$i months $bym-01"))
    是不是更清晰点呢?
      

  9.   

    strtotime($bym .'01') 也是一样的结果。如果因为格式的问题那么我直接常数调用怎么会出现正确的结果?
    //initRows1('2013-12', '2014-02');//initRows1方法正确输出
      

  10.   

    找到问题所在了,这个方法
    function initRows1($bym,$eym){ //判断两个日期间相差多少月
    $bym_list=explode("-",$bym);
    $eym_list=explode("-",$eym);
    if($bym_list[0]==$eym_list[0]){
    $months=abs($bym_list[1]-$eym_list[1]);
    }else{
    $months=abs(($eym_list[0]-$bym_list[0]-1)*12)+abs($eym_list[1]+(12-$bym_list[1]));
    }
       echo $bym."^---^".$eym."yyy".$months."<br>";
    $items=array();
    for ($i=0;$i<=$months;$i++){
           echo "xxxx ".$i."--".date("Y-m",strtotime("+$i months",strtotime($bym.'01')))."****".$bym."<br>";
    echo "<th colspan='3'><strong>".substr(getMonth(date("Y-m", strtotime("+$i months $bym-01"))),-4).substr(getMonth(date("Y-m", strtotime("+$i months $bym-01"))),0,-4)."</strong></th>";
    }}
    当用initRows1('2013-12', '2014-02');//initRows1方法正确输出当用//echo $btime."***--".$etime;//输出 '2013-12'***'2014-02' 
    initRows1($btime, $etime);//同样的参数输出却不正确为什么会这样??
      

  11.   


    function initRows1($bym,$eym){
     
        //判断两个日期间相差多少月
        $bym_list=explode("-",$bym);
        $eym_list=explode("-",$eym);
        if($bym_list[0]==$eym_list[0]){
            $months=abs($bym_list[1]-$eym_list[1]);
        }else{
            $months=abs(($eym_list[0]-$bym_list[0]-1)*12)+abs($eym_list[1]+(12-$bym_list[1]));
        }
           echo $bym."^---^".$eym."yyy".$months."<br>";
        $items=array();
        for ($i=0;$i<=$months;$i++){
           echo "xxxx ".$i."--".date("Y-m",strtotime("+$i months",strtotime($bym.'01')))."****".$bym."<br>";
            echo "<th colspan='3'><strong>".substr(getMonth(date("Y-m", strtotime("+$i months $bym-01"))),-4).substr(getMonth(date("Y-m", strtotime("+$i months $bym-01"))),0,-4)."</strong></th>";
        }
     
    }注意这算相差了多少个月的方法,同样的参数进去出来了不同结果
      

  12.   

    echo $btime."--".$etime."<br>";//输出 '2013-12'***'2014-02'
    //$btime=date('Y-m-d',strtotime($btime."-01"));//1970-01
    //$etime=date('Y-m-d',strtotime($etime."-01"));//1970-01
    //$btime=strtotime($btime."-01");//1970-01
    //$etime=strtotime($etime."-01");
    $btime=date('Y-m',strtotime($btime));//1970-01
    $etime=date('Y-m',strtotime($etime));
    echo $btime."--**--".$etime."<br>";// 
    ‘2013-12’怎么转化为date格式的‘2013-12’?
      

  13.   

    php 5.4.20
    $btime = '2013-12';
    echo $btime = date('Y-m',strtotime($btime));//2013-12php 5.4 之前
    $btime = '2013-12';
    echo $btime = date('Y-m',strtotime("$btime-01"));//2013-12
      

  14.   

    我的php版本是5.2.6,已经尝试了各种方法还是不能正确转换
    <?php$btime= "<script>document.write(betime1)</script>";
    $etime="<script>document.write(endtime1)</script>";
    $x=$btime;
    echo $btime."<br>";//2013-12
    if(is_object($btime)){
    echo "----";
    }else{
    echo "bbb";
    if(is_string($x)){
    echo "iii";
    }else{
    echo "kkk";
    }
    }
    if($x=='2013-12'){//不相等
    echo "xxx<br>";
    }
    echo "strtotime:".strtotime("$x-01")."<br>";//输出空
    echo date('Y-m',strtotime("$btime-01"));//1970-01initRows1('2013-12', '2014-02');//initRows1方法正确输出
    //initRows1($btime,$etime);
    //$btime="<script>document.getElementById('bt').value</script>";
    //$etime="<script>document.getElementById('et').value</script>";
    //echo $btime."-输入-".$etime."<br>";//输出 '2013-12'***'2014-02'
    //$btime=date('Y-m-d',strtotime($btime."-01"));//1970-01
    //$etime=date('Y-m-d',strtotime($etime."-01"));//1970-01
    //$btime=strtotime($btime."-01");//1970-01
    //$etime=strtotime($etime."-01");
    //$btime=strtotime($btime);//空
    //$etime=strtotime($etime);
    //echo $etime."^^^".$btime."<br>";
    //$etime=date('Y-m',strtotime($etime));
    //$btime=date('Y-m',strtotime($btime));
    //echo $btime = date('Y-m',strtotime($btime));//1970-01
    //$btime = date('Y-m',strtotime("$btime-01"));////1970-01
    //echo $btime."--**--".$etime."<br>";// //$btime=(int)$btime;
    //$etime=(int)$etime;
    //$bt=date("Y-m",strtotime("-3 month"));
    //$et=date("Y-m",strtotime("-1 month"));
    //$x=date('Y-m',strtotime($btime));;
    //$y=date('Y-m',strtotime($etime));;
    //echo "test".strtotime("$btime.-01")."<br>";
    //echo $etime."***".$btime."---".$x."&&&".$y."<br>";//initRows1(date("Y-m",strtotime("-3 month")), date("Y-m",strtotime("-1 month")));//同样的参数输出却不正确 //initRows1('2013-12', '2014-02');//initRows1方法正确输出
    ?>
      

  15.   

    function initRows1($bym,$eym){
      echo "$bym,$eym<br>"; //加上这句,看看传入的都是什么  
        //判断两个日期间相差多少月观察你注释掉的代码,你根本就没有从客户端取到数据
      

  16.   

    输出:2013-12,2014-02
    我是用js获取的上元素的值,在传给本页面对应的php,功能是在easyui datagrid上实现动态加载列,根据用户选择的不同时间段对应生成不同的列,代码如下:
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
    <title>salesquantityper</title>
    <link rel="stylesheet" type="text/css" href="http://www.java1234.com/jquery-easyui-1.3.3/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="http://www.java1234.com/jquery-easyui-1.3.3/themes/icon.css">
    <link rel="stylesheet" type="text/css" href="http://www.java1234.com/jquery-easyui-1.3.3/demo/demo.css">
    <script type="text/javascript" src="http://www.java1234.com/jquery-easyui-1.3.3/jquery.min.js"></script>
    <script type="text/javascript" src="http://www.java1234.com/jquery-easyui-1.3.3/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="http://www.java1234.com/jquery-easyui-1.3.3/locale/easyui-lang-zh_CN.js"></script>

    <style type="text/css">
    .box{position:relative;}
    .tip{position:absolute;border:2px solid #000;}
    </style>
    </head>
    <body>
    <!-- 级联菜单 -->
    <!-- 筛选列表 -->
    <div style="background-color:EFF7FB">
    <form id="form1" style="margin-bottom:0px;" action="get_bestlist.php">
    <table>
    <tr>
    <td><h4>Search:</h4></td>

    <td><input class="easyui-datebox" id="bt" name="bt"  value=<?php 
    $bt=date("Y-m",strtotime("-3 month"));
    $et=date("Y-m",strtotime("-1 month"));
    echo $bt;
    ?>></input></td><td>--to--</td>
    <td><input id="et" name="et" class="easyui-datebox"  value=<?php
    echo $et;

    ?>></td>
    <td> Resgion: <select id="area" name="area" class="easyui-combobox" name="area" data-options=" multiple:true" onchange="areaChanged(this.value)" style="width:150px;">
            <option value="'E','N','H','S','C','W','F'">All Region</option>
            <option value="'E'">East</option>
            <option value="'N'">North</option>
            <option value="'H'">Center</option>
            <option value="'S'">South</option>
            <option value="'C'">NorthEast</option>
            <option value="'W'">Western</option>
            <option value="'F'">Distribution area</option>
            
            
        </select>
        &nbsp;
    </td>
    <td>Category: <select id="level" class="easyui-combobox" name="level" data-options=" multiple:true" style="width:150px;">
            <option value="'A+','A-','A','B','C','D'">All Level</option>
            <option value="'A+','A-','A'">A</option>
            <option value="'B'">B</option>
            <option value="'C'">C</option>
            <option value="'D'">D</option>
            <option value="'OUTLETS'">OUTLETS</option>
        </select>
    &nbsp;
    </td> <TD><input type="button" id="but"  value="go"  ></TD>
    </tr>
    </table>
    </form> <br>
    <div><p>Default show the data of last 3 months</p>&nbsp;</div> </div>
    <br>
    <script >
    //alert($('#bt').datebox('getValue'));
    var betime1=document.getElementById('bt').value;
    var endtime1=document.getElementById('et').value;//var xx="kokjh";
    jQuery(document).ready(function(){
    //var betime=$('#bt').datebox('getValue');
    //var endtime=$('#et').datebox('getValue');
        $('#but').click(function(){  
           //alert($('#bt').datebox('getValue')+"***"+$('#et').datebox('getValue'));
    $('#salesquantityper').datagrid('reload',{area:$('#area').combobox('getValues'),level:$('#level').combobox('getValues'),bt:$('#bt').datebox('getValue'),et:$('#et').datebox('getValue')});
         });});
    </script>
    <!-- bestline表格 --> 
    <?php 
    //"<script>document.write(betime)</script>", "<script>document.write(betime)</script>"
    //echo "<script>document.write(betime)</script><br>";
    //echo "<script>document.write(endtime)</script><br>";//月份的英文转换
    function getMonth($str_ym){
    //echo "<br>getmonth".$str_ym."<br>";
    $ym_list=explode("-",$str_ym);
    $yy.=$ym_list[0];
    $mm=$ym_list[1];
    switch ($mm) {
    case 01 :
    return "January".$yy;
    break;
    case 02:
    return "February".$yy;
    break;
    case 03 :
    return "March".$yy;
    break;
    case 04 :
    return "April".$yy;
    break;
    case 05:
    return "May".$yy;
    break;
    case 06 :
    return "June".$yy;
    break;
    case 07 :
    return "July".$yy;
    break;
    case 08 :
    return "Aguest".$yy;
    break;
    case 09 :
    return "September".$yy;
    break;
    case 10:
    return "October".$yy;
    break;
    case 11 :
    return "November".$yy;
    break;
    case 12 :
    return "December".$yy;
    break;}
    }//生成列function xx1($str1){
    $strt=substr($str1,0,4).'-';
    return $strt.substr($str1,4,6);
    }
    function initRows1($bym,$eym){
    echo "^^^^^^^^^$bym,$eym<br>"; //加上这句,看看传入的都是什么
    //判断两个日期间相差多少月
    $bym_list=explode("-",$bym);
    $eym_list=explode("-",$eym);
    if($bym_list[0]==$eym_list[0]){
    $months=abs($bym_list[1]-$eym_list[1]);
    }else{
    $months=abs(($eym_list[0]-$bym_list[0]-1)*12)+abs($eym_list[1]+(12-$bym_list[1]));
    }
     //  echo $bym."^---^".$eym."yyy".$months."<br>";
    $items=array();
    for ($i=0;$i<=$months;$i++){
          // echo "xxxx ".$i."--".date("Y-m",strtotime("+$i months",strtotime($bym.'-01')))."****".$bym."<br>";
    echo "<th colspan='3'><strong>".substr(getMonth(date("Y-m", strtotime("+$i months $bym"))),-4).substr(getMonth(date("Y-m", strtotime("+$i months $bym"))),0,-4)."</strong></th>";
    }}function initRows2($bym,$eym){
    //判断两个日期间相差多少月
    $bym_list=explode("-",$bym);
    $eym_list=explode("-",$eym);
    if($bym_list[0]==$eym_list[0]){
    $months=abs($bym_list[1]-$eym_list[1]);
    }else{
    $months=abs(($eym_list[0]-$bym_list[0]-1)*12)+abs($eym_list[1]+(12-$bym_list[1]));
    } $items=array();
    for ($i=0;$i<=$months;$i++){
    echo"<th data-options=field:'".getMonth(date("Y-m", strtotime("+$i months $bym-01")))."_Number_stores' width='80' align='right'><strong>Nubmer of<br> Stores</strong></th>";
          echo"<th field='".getMonth(date("Y-m", strtotime("+$i months $bym-01")))."_Quantity_sold' width='100'  align='right'><strong>Quantity Sold</strong></th>";
          echo"<th field='".getMonth(date("Y-m", strtotime("+$i months $bym-01")))."_qn' width='120'  align='right'><strong>Average qty <br>Sold per store</strong></th>";
    }}?>

    <table id="salesquantityper"  class="easyui-datagrid" style="width:auto;height:220px" title="Stores sales quantity performance"
     data-options="url: 'get_salesquantityper.php', singleSelect: true,  rownumbers:true "      
     > 
    <thead data-options="frozen:true"> 
    <tr> 
    <th data-options="field:'Category'"  width="100" ><strong>Category</strong></th>
    </tr> 
    </thead> 
    <thead >
    <tr>
    <?php$btime= "<script>document.write(betime1)</script>";
    $etime="<script>document.write(endtime1)</script>";
    $x=$btime;
    echo $btime."<br>";//2013-12
    if(is_object($btime)){
    echo "----";
    }else{
    echo "bbb";
    if(is_string($x)){
    echo "iii";//输出
    }else{
    echo "kkk";
    }
    }
    if($x=='2013-12'){//不相等
    echo "xxx<br>";
    }
    echo "strtotime:".strtotime("$x-01")."<br>";//输出空
    echo date('Y-m',strtotime("$btime-01"));//1970-01//initRows1('2013-12', '2014-02');//initRows1方法正确输出
    initRows1($btime,$etime);
    //$btime="<script>document.getElementById('bt').value</script>";
    //$etime="<script>document.getElementById('et').value</script>";
    //echo $btime."-输入-".$etime."<br>";//输出 '2013-12'***'2014-02'
    //$btime=date('Y-m-d',strtotime($btime."-01"));//1970-01
    //$etime=date('Y-m-d',strtotime($etime."-01"));//1970-01
    //$btime=strtotime($btime."-01");//1970-01
    //$etime=strtotime($etime."-01");
    //$btime=strtotime($btime);//空
    //$etime=strtotime($etime);
    //echo $etime."^^^".$btime."<br>";
    //$etime=date('Y-m',strtotime($etime));
    //$btime=date('Y-m',strtotime($btime));
    //echo $btime = date('Y-m',strtotime($btime));//1970-01
    //$btime = date('Y-m',strtotime("$btime-01"));////1970-01
    //echo $btime."--**--".$etime."<br>";// //$btime=(int)$btime;
    //$etime=(int)$etime;
    //$bt=date("Y-m",strtotime("-3 month"));
    //$et=date("Y-m",strtotime("-1 month"));
    //$x=date('Y-m',strtotime($btime));;
    //$y=date('Y-m',strtotime($etime));;
    //echo "test".strtotime("$btime.-01")."<br>";
    //echo $etime."***".$btime."---".$x."&&&".$y."<br>";//initRows1(date("Y-m",strtotime("-3 month")), date("Y-m",strtotime("-1 month")));//同样的参数输出却不正确 //initRows1('2013-12', '2014-02');//initRows1方法正确输出
    ?>
    </tr> 
    <tr> 
    <?php //echo $btime."***".$etime;//输出 '2013-12'***'2014-02'
    //initRows2($btime, $etime);
    initRows2('2013-12', '2014-02');
    ?> 
    </tr> 
    </thead> 
    </table></body>
    </html>
      

  17.   

    $btime= "<script>document.write(betime1)</script>";
    $etime="<script>document.write(endtime1)</script>";
    initRows1($btime,$etime);
    这能对吗?
      

  18.   

    echo $btime;
    能正确输出值....那该怎么改呢?
      

  19.   

    你在浏览器中查看源文件,还能看到正确的结果吗?betime1 是 js 的变量,你不发送到服务端,php 能得到吗?
      

  20.   

    浏览器中查看源文件,看不到php的内容,当日就看不到结果。 php是运行在服务器端的,betime如果没有传到服务端那这段代码怎么会输出正确的结果?大神怎么修改呢?
      

  21.   

    表单提交、ajax 提交,总之要根据你客户端代码来决定
      

  22.   

    jquery  .get 不就可以了?