从文本文件中读取,然后决定是要禁用还是启用php中的按钮

Read from a text file and then decide wether we want to disable or enable a button in php

本文关键字:启用 php 按钮 读取 文本 然后 决定 文件      更新时间:2023-09-26
     $filename ="E:''Serialportread''boxcheck.txt";
    $handle = fopen($filename, "r");
    $data = fread($handle, filesize($filename));
    fclose($handle);
if($data=="CLOSED")
{
echo'<td><button id="read" class="bott2" style="margin-top:18px;">Read</button></td><td>';
}
else{
echo'<td><button id="read" class="bott2" style="margin-top:18px;" disabled="disabled">Read</button></td><td>';
}

这发生在点击之前。

下面的代码是点击功能定义的:

$('#read').click(function(e){
    var fso1, ForReading;
    ForReading = 1;var status;
    fso1 = new ActiveXObject("Scripting.FileSystemObject");
    file = fso1.OpenTextFile("E:''Serialportread''boxcheck.txt", ForReading, false, -2);
    status = file.ReadLine();
    file.Close();
    alert(status);
    if(status=='CLOSED')
    {
      alert('ysess');
      $.fn.a();
      e.preventDefault();
      }
      else{
      alert('error')
    $('#read').html('');
      str='<diasabled="disabled">';
      $('#read').append(str);
    alert('yes');

      }
    });

两个代码都不起作用。我也尝试了另一个代码,但它一次又一次地刷新我的页面,这是我不想要的。

中存在语法错误

str='<diasabled="disabled">';

diA军刀

你应该尽量不要干扰HTML,而是使用样式:

if(status=='CLOSED')
{
  alert('ysess');
  var cb = $("#read");
  cb.removeAttribute("disabled");
  removeClass(cb, "button-disabled"); 
}
else
{
  alert('error')
  var cb = $('#read');
  // visually change the button - otherwise it does not look as disabled
  addClass(cb, "button-disabled"); 
  cb.setAttribute("disabled","");
  alert('yes');
}