duanao4729
2015-11-18 17:18
浏览 13

Jquery检查是否有东西在PHP中发布了$ _POST

I haven't been able to find an answer to this that works. All I want to do is check with Jquery to see if something has been posted in PHP.

PHP:

if ($_POST['clockin'] == "Clock In") {  
    //some code
};

And for the Jquery:

if (<?php $_POST['clockin'] == "Clock In" ?>) {
        $("#clockin").click(function(){
            $(this).attr('disabled', 'disabled');
            $("#clockout").removeAttr('disabled');
        });
    };

图片转代码服务由CSDN问答提供 功能建议

我无法找到有效的答案。 我想做的就是检查Jquery,看看是否已经在PHP中发布了一些内容。

PHP:

  if($ _POST ['clockin'] ==“Clock In”){
 //一些代码 
}; 
   
 
 

对于Jquery:

  if(&lt;?php $ _POST ['  clockin'] ==“Clock In”?&gt;){
 $(“#clockin”)。click(function(){
 $(this).attr('disabled','disabled'); 
  $(“#clockout”)。removeAttr('disabled'); 
}); 
}; 
   
 
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dtmsaqtly798322992 2015-11-18 17:20
    已采纳

    Try this,

    <?php if ( isset($_POST['clockin'])) { 
        if ( $_POST['clockin'] == "Clock In") { ?>
            $("#clockin").click(function(){
                $(this).attr('disabled', 'disabled');
                $("#clockout").removeAttr('disabled');
            });
    <?php } } ?>
    

    Make sure you enclose script with <script></script> tags.

    已采纳该答案
    打赏 评论
  • douxin20081125 2015-11-18 17:56

    You shouldn't mix Server and Client Code(JS) unless you have no option but you can embed php in html thats advantage of scripting If you want to check it on Page load if previous page was form submission

    Use Flag to check whether clock in is set php

    <?php
      $flag=false;
       if ($_POST['clockin'] == "Clock In") {  
            $flag=true;
       }
    ?> 
    

    html

    <html>
       <body>
           <form onsubmit="return changeAttr(<?php echo $flag ?>);"> 
               <input type="submit" id="clockin" />
               <input id="clockout" />
          </form>
       </body>
    </html>
    

    JS

    function changeAttr(flag) {
      //alert(flag);
      var clckin = document.getElementById('clockin');
      var clckout = document.getElementById('clockout');
      if (flag) {
        clckin.disabled = true;
        clckout.disabled = false;
        return false;
      }
      return true;
    }
    
    打赏 评论

相关推荐 更多相似问题