为啥所有按钮只控制同一行数据?
为啥所有按钮只控制同一行数据?应该怎么解决啊。
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Insert title here</title><script language="javascript" type="text/javascript"> function showtd(num) { document.getElementById("bg"+num).style.display = "none"; document.getElementById("show"+num).style.display = "block"; document.getElementById("ba"+num); document.getElementById("gn"+num); } function hidetd(num) { document.getElementById("bg"+num).style.display = 'block'; document.getElementById("show"+num).style.display = 'none'; } function showtext(){ document.getElementById("a").removeAttribute("readOnly"); document.getElementById("b").removeAttribute("readOnly"); document.getElementById("c").removeAttribute("readOnly"); document.getElementById("d").removeAttribute("readOnly"); document.getElementById("e").removeAttribute("readOnly"); document.getElementById("f").removeAttribute("readOnly"); } function hidetext(){ document.getElementById("a").readOnly="true"; document.getElementById("b").readOnly="true"; document.getElementById("c").readOnly="true"; document.getElementById("d").readOnly="true"; document.getElementById("e").readOnly="true"; document.getElementById("f").readOnly="true"; } </script></head><body> <form> <table border="1"> <?php $db = mysql_connect('localhost','root','root'); mysql_select_db('ec',$db); if (!$db) { die('Could not connect: ' . mysql_error()); } $result = mysql_query("select * from goods"); echo "<tr> <th>GoodsID</th> <th>BarCode</th> <th>GoodsName</th> <th>Category</th> <th>Specifications</th> <th>Manufacturers</th> <th>Numbers</th> <th>Instructions</th> <th>Pictures</th> <th>Update</th> <th>Delete</th> </tr>"; $n = 0; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['id'] . "</td>"; echo "<td>" . "<input type='text' id='a' value='$row[barcode]' style='width:60px;border:0px' readOnly>" . "</td>"; echo "<td>" . "<input type='text' id='b' value='$row[goods_name]' style='width:90px;border:0px' readOnly>" . "</td>"; echo "<td>" . $row['category'] . "</td>"; echo "<td>" . "<input type='text' id='c' value='$row[specifications]' style='width:90px;border:0px' readOnly>" . "</td>"; echo "<td>" . "<input type='text' id='d' value='$row[manufacturers]' style='width:90px;border:0px' readOnly>" . "</td>"; echo "<td>" . "<input type='text' id='e' value='$row[number]' style='width:60px;border:0px' readOnly>" . "</td>"; echo "<td>" . "<input type='text' id='f' value='$row[instruction]' style='width:80px;border:0px' readOnly>" . "</td>"; echo "<td>" . "<img src = '$row[picture_url]' style="max-width:90%"/ alt="为啥所有按钮只控制同一行数据?" >" . "</td>"; echo "<td id='bg$n'>". "<input id='btnshow$n' type='button' value='Update' onclick='showtd($n);showtext()' />". "</td>". "<td id='show$n' style='display:none'>". "<input id='btnclose$n' type='button' value='Save' onclick='hidetd($n);hidetext()'/>". "</td>"; echo "<td>"."<a href='delete.php?id=$row[id]'>"."Delete"."</a>"."</td>"; echo "</tr>"; ++$n; } mysql_close($db);?> </table></form></body></html>
回复讨论(解决方案)
总觉得你这代码有一堆语法问题啊
总觉得你这代码有一堆语法问题啊
可以正常运行。
循环输出有多少个id='a'呢?
然后 document.getElementById("a") 会得到什么……
什么情况?数据库读出来ID都对的吧?这个应该id有传过去吧,再试试吧~
循环输出有多少个id='a'呢?
然后 document.getElementById("a") 会得到什么……
我也觉得是这个id的问题,就是不知道怎么改。
什么情况?数据库读出来ID都对的吧?这个应该id有传过去吧,再试试吧~
a标签读出来的id是我在数据库内设置的主键,和d的id是两码事。
引用 1 楼 chendong_j 的回复:
总觉得你这代码有一堆语法问题啊
可以正常运行。
顿时感觉lz好强大
你每行同一列的 id 都相同,怎么能用 getElementById 来定位呢?
65-71行 设置的id都是重复的 如果区分的话可以把设置的ID(a,b,c...)前拼接上$row['id']加以区分

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

长URL(通常用关键字和跟踪参数都混乱)可以阻止访问者。 URL缩短脚本提供了解决方案,创建了简洁的链接,非常适合社交媒体和其他平台。 这些脚本对于单个网站很有价值

在Facebook在2012年通过Facebook备受瞩目的收购之后,Instagram采用了两套API供第三方使用。这些是Instagram Graph API和Instagram Basic Display API。作为开发人员建立一个需要信息的应用程序

Laravel使用其直观的闪存方法简化了处理临时会话数据。这非常适合在您的应用程序中显示简短的消息,警报或通知。 默认情况下,数据仅针对后续请求: $请求 -

这是有关用Laravel后端构建React应用程序的系列的第二个也是最后一部分。在该系列的第一部分中,我们使用Laravel为基本的产品上市应用程序创建了一个RESTFUL API。在本教程中,我们将成为开发人员

Laravel 提供简洁的 HTTP 响应模拟语法,简化了 HTTP 交互测试。这种方法显着减少了代码冗余,同时使您的测试模拟更直观。 基本实现提供了多种响应类型快捷方式: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

PHP客户端URL(curl)扩展是开发人员的强大工具,可以与远程服务器和REST API无缝交互。通过利用Libcurl(备受尊敬的多协议文件传输库),PHP curl促进了有效的执行

您是否想为客户最紧迫的问题提供实时的即时解决方案? 实时聊天使您可以与客户进行实时对话,并立即解决他们的问题。它允许您为您的自定义提供更快的服务

2025年的PHP景观调查调查了当前的PHP发展趋势。 它探讨了框架用法,部署方法和挑战,旨在为开发人员和企业提供见解。 该调查预计现代PHP Versio的增长
