从文本文件中读取,然后决定是否要在php中禁用或启用按钮
16lz
2021-01-22
$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>';
}
this happening before click.
在点击之前发生这种情况。
code below is on click function defined :
以下代码定义了点击功能:
$('#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');
}
});
Both the codes are not working. I tried another code as well but that was refreshing my page again and again which i don't want .
这两个代码都不起作用。我也尝试了另一个代码,但这一次又一次刷新我的页面,我不想要。
1 个解决方案
#1
0
There is a syntax error in
语法错误
str='<diasabled="disabled">';
diAsabled
You should better try not to mess with the HTML - use style instead:
你最好尽量不要乱用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');
}
更多相关文章
- php mail函数一段好的代码
- 用于上传多个文件的PHP代码
- (phpQuery)对网站产品信息采集代码的优化
- 韩顺平_php从入门到精通_视频教程_学习笔记_源代码图解_PPT文档
- 【MySQL 技巧分享】 mysql -e 加 v 简化代码
- Oracle相当于MySQL代码“插入虚拟”以返回错误消息
- 登录使用PHP并´t显示任何html代码
- 在代码点火器中从mysql迁移到postgresql
- 【动软.Net代码生成器】连接MySQL生成C#的POCO实体类(Model)