普通网友 2014-08-15 17:39
浏览 47
已采纳

按钮上的预定义时间+倒计时使按钮可点击

I´m a totally newbie in Javascript.

I´m using Wordpress and need a Button that is getting clickable after a predefined time - Like 2 Hours after Posts.

Here´s what i already have.

  echo $post_time = $proposal->comment_date;
  $t_time = get_the_time( __( 'Y/m/d g:i:s A' ) );
  echo "<h1>BLOG TIME</h1>";
  echo $t_time . "<br>";
  echo $current_time = date("Y-m-d g:i:s A");
  $time_to_wait = 60 //Minutes

  if ( $post_time < $current_time )
  {
    echo "ok";
  } else { echo "not ok"; } 
  1. How to integrate the $time_to_wait Variable?

  2. How should the JavaScript look like?

  • 写回答

1条回答 默认 最新

  • duanmu2941 2014-08-15 17:52
    关注

    How to integrate the $time_to_wait Variable?

    $post_time and $current_time should be timestamps. $time_to_wait should be milliseconds (60 * 60 * 1000)

    Maybe like that: if ($current_time - $time_to_wait > $post_time) { echo '0'; } else { echo '1'; }

    (if i understood your question correctly)

    How should the JavaScript look like?

    Please, describe what do you want? I think it should be like

    echo '<button id="your_button" ' . (($current_time - $time_to_wait > $post_time) ? 'disabled="true"' : ''). '">' in your php code.

    If you want button to be enabled if time has passed. No JS required. Did i answered your question correctly? If not, please response.

    (Excuse me for my grammar)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 shape_predictor_68_face_landmarks.dat
  • ¥15 slam rangenet++配置
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题