draxu26480 2012-07-10 08:50
浏览 76
已采纳

基于IF语句通过PHP调用JS函数的问题

I have a web based tool. There is a login where username, loggedin and authorised are stored in session variables.

There is one particular page where I have a form that has multiple buttons, I wish to disable one button based on what the users authorisation level is. So if authorised is 0 (user) the button is disabled, else it's enabled as I've only got two authorisation levels, 0 & 1.

I've attached what I've done below, and to me it looks right, obviously it's not!

Here is the JQuery function:

$(function disable(){
  $('#signBtn').attr('disabled', true);
});

Here is the PHP code:

if($_SESSION['authorised'] == '0') 
{
    echo "<SCRIPT LANGUAGE='javascript'>disable();</SCRIPT>";
}

Here is my HTML code:

   <input type=\"submit\" name=\"save\"  id = \"signBtn\" class = 'eBtnSubmit' value=\"Sign off by Chairperson\" />

If there is anyone out there that can see what my problem is I would really appreciate it...this is my last piece of the puzzle and I'm presenting this today (Software Intern).

So basically if the level is 0 call the function.

Regards, Gary

  • 写回答

3条回答 默认 最新

  • dongsimu4422 2012-07-10 09:01
    关注

    It might be easier to simply set the value in the HTML if possible

    if($_SESSION['authorised'] == '0'){
        echo '<button type="button" disabled="disabled">Click Me!</button>';
    }else{
        echo '<button type="button">Click Me!</button>';
    }
    

    This would work before the page even starts loading.

    The other option would be to hook the window on load function.

    window.onload = (function(){ [...] }

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大