我想在php中的表td中调用javascript函数

时间:2017-05-23 07:39:47

标签: javascript php

我想从表td调用javascript函数并将此td值作为此javascript函数的参数传递。这是我的剧本和表格。

<table width="100%" class="track">
                    <tr>
                        <th colspan="2">Load Information</th>
                    </tr>                     
                    <tr>
                        <td>LOAD  DATE:</td>
                        <td id="ldate"><?php echo $datas[0]->DATE?> </td>
                    </tr>
                </table>
<script>
       function formatDate(date_string) {
            var date = new Date(date_string);
            var monthNames = [
                "January", "February", "March",
                "April", "May", "June", "July",
                "August", "September", "October",
                "November", "December"
            ];
            var day = date.getDate();
            var monthIndex = date.getMonth();
            var year = date.getFullYear();

            if (day < 10) {
                day = '0' + day;
            }
            return  monthNames[monthIndex] + ' ' + day + ', ' + year ;
        } 
    </script>

我希望显示类似MARCH 03,2016的日期格式,但我的实际格式将显示为2016-03-03。

1 个答案:

答案 0 :(得分:1)

使用PHP {/ 1}}和strtotime()

date()