[英]JavaScript Button Enable and Disable with PHP
I have a while loop that fetches data from a database. 我有一个while循环从数据库中获取数据。 I have made three buttons: 我做了三个按钮:
> Open
> Hold
> Close
The first time when the page loads, only the open button should be enabled, and the others should be disabled. 第一次加载页面时,只应启用打开按钮,并禁用其他按钮。
After I click the open button, the open button should be disabled, and the hold and close buttons should be enabled. 单击打开按钮后,应禁用打开按钮,并应启用保持和关闭按钮。
I got this result for only one row, but in the while loop not for all the rows. 我得到的结果只有一行,但在while循环中不是所有的行。
I have used JavaScript with php. 我用过PHP的JavaScript。
Example: 例:
function onload()
{
document.getElementById("Hold").disabled = true;
document.getElementById("close").disabled = true;
return false;
}
The above code was working for the first row, but I need it to work for all the while loop values. 上面的代码适用于第一行,但我需要它来处理所有while循环值。
Your problem lies in that you are using the same ID for multiple elements - ID's must be unique to each element, and thus, getElementById returns ONE element, with that ID. 您的问题在于您对多个元素使用相同的ID - 每个元素的ID必须是唯一的,因此,getElementById返回带有该ID的ONE元素。 Give them classes instead. 改为给他们上课。
<input type="button" value="Open" id="openButton" name="openButton">
<input type="button" value="Hold" id="holdButton" name="holdButton" disabled="disabled">
<input type="button" value="Close" id="closeButton" name="closeButton" disabled="disabled">
$(document).on('click','input[type=button]', function() {
buttonVal = $(this).val();
if(buttonVal == 'Open' )
{
$(this).prop("disabled", true);
$('#holdButton,#closeButton').prop("disabled", false);
}
else
{
$('#holdButton,#closeButton').prop("disabled", true);
$('#openButton').prop("disabled", false);
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.