$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');
}