PHP和JavaScript日期不匹配 - 奇怪的异常

HTML/PHP:

<button onclick="change_value(<?php echo $date?>)">Go</button>

JavaScript:

function change_value(date_used)
{
    alert(date_used);
}

When I right-click on the button and click the "Inspect Element" button shows the parameter correctly, i.e something like this:

<button onclick="change_value(2012-08-22)">Go</button>

But the alert in the JavaScript is displaying 1981. That's it - only 1981. Not only the date is wrong, but the format, too.

What is this happening and how can I fix it?

Change

<button onclick="change_value(<?php echo $date?>)">Go</button>

to this:

<button onclick="change_value('<?php echo $date?>')">Go</button>

You should pass it as string to JavaScript ...