gpt4 book ai didi

php - 禁用和启用 onclick 事件不适用于多行

转载 作者:行者123 更新时间:2023-11-29 00:32:26 25 4
gpt4 key购买 nike

我正在做一个 php 项目,

好吧,我需要帮助,因为我有 10 条记录要将数据更新到数据库,请参阅下面的诊断-

enter image description here

现在就像您看到的 No_Info 选项一样,表示:No_Data 和 Available。

因此,当用户点击 ID:1 的 No_data 时,它会禁用附加到相应 ID 的字段。以及相同的可用作品。

但它只对 ID: 1 起作用,对其他行不起作用.....

编辑:在此处更新代码。

>>>> <?php
//connect to the database server
$objConnect = mysql_connect("localhost","root","") or die(mysql_error());
//select the database
$objDB = mysql_select_db("main_project");
//select which data you want to get.
$sql = "SELECT * FROM website_maindb";
$objQuery = mysql_query($sql);
// $Ct = mysql_query('select * from company_type');
/* $objResult = mysql_fetch_array($objQuery); // Not to use when using loop to call full database */
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>ss</title>
<script>
function disable()
{
document.getElementById("noi1").disabled=true;
document.getElementById("noi2").disabled=true;
document.getElementById("noi3").disabled=true;
document.getElementById("noi4").disabled=true;
document.getElementById("noi5").disabled=true;
document.getElementById("noi6").disabled=true;

}
function enable()
{
document.getElementById("noi1").disabled=false;
document.getElementById("noi2").disabled=false;
document.getElementById("noi3").disabled=false;
document.getElementById("noi4").disabled=false;
document.getElementById("noi5").disabled=false;
document.getElementById("noi6").disabled=false;
}
</script>
</head>
<body>

<form id="form" action="insert.php" method="post">
<table width="700" border="1">
<tr>
<th></th>
<th width="20"> <div align="center">ID </div></th>
<th width="98"> <div align="center">website </div></th>
<th width="98"> <div align="center">category </div></th>
<th width="98"> <div align="center">email </div></th>
<th width="98"> <div align="center">contact form </div></th>
<th width="98"> <div align="center">Primary No. </div></th>
<th width="98"> <div align="center">Secondary No. </div></th>
<th width="98"> <div align="center">fax </div></th>
<th width="98"> <div align="center">Company type </div></th>
<th width="98"> <div align="center">No_Info </div></th>
<th width="98"> <div align="center">time </div></th>
</th>
</tr>
<?php
$options = '';
$Ctype=mysql_query("select distinct typec from company_type");
while($row = mysql_fetch_array($Ctype)) {
$options .="<option>" . $row['typec'] . "</option>";
}
?>

<?php
$i = 0;
while($objResult = mysql_fetch_array($objQuery))
{
$i++;
?>
<tr>
<td><input type="hidden" name="WID" value="<?=$objResult["WID"];?>"></td>
<td><label><input type="text" name="ID" value="<?=$objResult["WID"];?>" disabled></label></td>
<td><input type="text" name="website" value="<?=$objResult["website"];?>"></td>
<td><input type="text" name="cat" size="10"></td>
<td><input type="text" id="noi1" name="email" size="10"></td>
<td><input type="text" id="noi2" name="cform" size="10"></td>
<td><input type="text" id="noi3" name="contactp" size="10"></td>
<td><input type="text" id="noi4" name="contacts" size="10"></td>
<td><input type="text" id="noi5" name="fax" size="10"></td>
<td><select id="Ctype" name="Ctype"> <?=" $options "?> </select></td>
<td><button type="button" onclick="disable()" size="20">No_Data</button> </br>
<button type="button" onclick="enable()" size="20">Available</button>
</td>
<td><input type="text" id="noi6" name="time" size="10"></td>
</tr>
<?php
}
?>
<button type="submit" id="send">Submit</button>
</form>
</table>
</body>
</html>

谁能帮忙解决一下..

最佳答案

你做的有点不对。您必须在数组中构建表单字段。像这样:

<input type="text" id="noi1_<?php echo $i; ?>" name="email[]" size="10">

.

你的按钮是这样的:

<button type="button" onclick="disable('<?php echo $i; ?>')" size="20">No_Data</button>

.

然后,在你的 JS 中:

function disable(idx)
{
document.getElementById("noi1_"+idx).disabled=true;
.
.

..

最后,当您在 $_POST 中收到表单时,您将获得 $_POST['email'] 作为数组。

关于php - 禁用和启用 onclick 事件不适用于多行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15919195/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com