开发者

javascript: quotes problem: <input ... onclick='....value=\'2011-01-07 19:37\';'> doesn't work?

开发者 https://www.devze.com 2023-02-02 21:40 出处:网络
Why does this not work, but is ok for \"Y-m-d\"? <?php echo \"<input id=mindate value=$mindate>

Why does this not work, but is ok for "Y-m-d"?

<?php
echo "<input id=mindate value=$mindate>
<input type=button value=Today 
onclick='javascript:document.getElementById(\'mindate\').value 
=\'".date("Y-m-d H:i:s")."\';'>";
?>

On the page it looks like:

<input type=button value=Today 
onclick='javascript:document.getElementById(\'mindate\').value
=\'2011-01-07 19:37:21\';'>

Must have something to开发者_C百科 do with all those quotes, but can't see where...


Use double quotes for your HTML attributes.

<?php
echo '<input id="mindate" value="$mindate">
<input type="button" value="Today" 
onclick="javascript:document.getElementById(\'mindate\').value 
=\'' . date("Y-m-d H:i:s") . '\';">';
?>


You need to use double quotes for mindate etc.. Try this:

  <?php echo "<input id=mindate value=$mindate> <input type=button value=Today   
      onclick='javascript:document.getElementById(\"mindate\").value  
     =\"".date("Y-m-d H:i:s")."\";'>"; 
  ?> 
0

精彩评论

暂无评论...
验证码 换一张
取 消