我希望点击“updqte”按钮后按钮变成“save”,然后单元格变成文本框,编辑完文本框后点击“save”结果提交给了数据库。按钮改变用js做完了,其他的实在是不回了,各位大神帮帮忙吧。
<!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"; } function hidetd(num) { document.getElementById("bg"+num).style.display = 'block'; document.getElementById("show"+num).style.display = 'none'; } function change() { var tds = document.getElementsByTagName("td"); var t1 = document.getElementById("a").innerHTML; var txt = document.createElement("input"); txt.type = "text"; txt.value = t1; txt.id = "sort_t"; tds[29].appendChild(txt); txt.select(); } function mouseup(){ if (document.getElementById("sort_t") && event.srcElement.id != "sort_t") { var obj = document.getElementById("sort_t").parentElement; var txtValue = document.getElementById("sort_t").value; obj.innerText = txtValue; } } </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>" . $row['barcode'] . "</td>"; echo "<td>" . $row['goods_name'] . "</td>"; echo "<td>" . $row['category'] . "</td>"; echo "<td>" . $row['specifications'] . "</td>"; echo "<td>" . $row['manufacturers'] . "</td>"; echo "<td>" . $row['number'] . "</td>"; echo "<td>" . $row['instruction'] . "</td>"; echo "<td>" . "<img src = '$row[picture_url]' style='width:80px;height=60px'/>" . "</td>"; echo "<td id='bg$n'>". "<input id='btnshow$n' type='button' value='Update' onclick='showtd($n)'/>". "</td>". "<td id='show$n' style='display:none'>". "<input id='btnclose$n' type='button' value='Save' onclick='hidetd($n)'/>". "</td>"; echo "<td>"."<a href='delete.php?id=$row[id]'>"."Delete"."</a>"."</td>"; echo "</tr>"; ++$n; } mysql_close($db); ?> </table></form> </body></html>
回复讨论(解决方案)
1.给你的save按钮一个onclick方法 点击后触发
2.用ajax 提交参数到后台,调用php程序
3.然后将接收内容提交到数据库
4.成功or失败返回到页面
你这里要用到ajax来提交数据
1.给你的save按钮一个onclick方法 点击后触发
2.用ajax 提交参数到后台,调用php程序
3.然后将接收内容提交到数据库
4.成功or失败返回到页面
<!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"; } function hidetd(num) { document.getElementById("bg"+num).style.display = 'block'; document.getElementById("show"+num).style.display = 'none'; } function change() { var tds = document.getElementsByTagName("td"); var t1 = document.getElementById("a").innerHTML; var txt = document.createElement("input"); txt.type = "text"; txt.value = t1; txt.id = "sort_t"; tds[30].appendChild(txt); txt.select(); } function mouseup(){ if (document.getElementById("sort_t") && event.srcElement.id != "sort_t") { var obj = document.getElementById("sort_t").parentElement; var txtValue = document.getElementById("sort_t").value; obj.innerText = txtValue; } } </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 id='a'>" . $row['barcode'] . "</td>"; echo "<td>" . $row['goods_name'] . "</td>"; echo "<td>" . $row['category'] . "</td>"; echo "<td>" . $row['specifications'] . "</td>"; echo "<td>" . $row['manufacturers'] . "</td>"; echo "<td>" . $row['number'] . "</td>"; echo "<td>" . $row['instruction'] . "</td>"; echo "<td>" . "<img src = '$row[picture_url]' style='width:80px;height=60px'/>" . "</td>"; echo "<td id='bg$n'>". "<input id='btnshow$n' type='button' value='Update' onclick='showtd($n);change()' />". "</td>". "<td id='show$n' style='display:none'>". "<input id='btnclose$n' type='button' value='Save' onclick='hidetd($n);mouseup()'/>". "</td>"; echo "<td>"."<a href='delete.php?id=$row[id]'>"."Delete"."</a>"."</td>"; echo "</tr>"; ++$n; } mysql_close($db); ?> </table></form> </body></html>
我表上红色的部分是一个数组,我想让这个数组变成动态的,要不然所有按钮都只操作一条数据。有什么好办法没?
1.给你的save按钮一个onclick方法 点击后触发
2.用ajax 提交参数到后台,调用php程序
3.然后将接收内容提交到数据库
4.成功or失败返回到页面
不好意思是第24行,刚才没标上颜色。
要是我做的话就是都设为隐藏的
一个.show()
一个.hide()
当点击完一个操作就触发函数转换到另一个按钮
建议lz选择jq选择器都很强大
搭配ajax 足够完成大量input提交工作
你这里要用到ajax来提交数据
<!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"; } function hidetd(num) { document.getElementById("bg"+num).style.display = 'block'; document.getElementById("show"+num).style.display = 'none'; } function change() { var tds = document.getElementsByTagName("td"); var t1 = document.getElementById("a").innerHTML; var txt = document.createElement("input"); txt.type = "text"; txt.value = t1; txt.id = "sort_t"; tds[29].appendChild(txt); txt.select(); } function mouseup(){ if (document.getElementById("sort_t") && event.srcElement.id != "sort_t") { var obj = document.getElementById("sort_t").parentElement; var txtValue = document.getElementById("sort_t").value; obj.innerText = txtValue; } } </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 id='a'>" . $row['barcode'] . "</td>"; echo "<td>" . $row['goods_name'] . "</td>"; echo "<td>" . $row['category'] . "</td>"; echo "<td>" . $row['specifications'] . "</td>"; echo "<td>" . $row['manufacturers'] . "</td>"; echo "<td>" . $row['number'] . "</td>"; echo "<td>" . $row['instruction'] . "</td>"; echo "<td>" . "<img src = '$row[picture_url]' style='width:80px;height=60px'/>" . "</td>"; echo "<td id='bg$n'>". "<input id='btnshow$n' type='button' value='Update' onclick='showtd($n);change()' />". "</td>". "<td id='show$n' style='display:none'>". "<input id='btnclose$n' type='button' value='Save' onclick='hidetd($n);mouseup()'/>". "</td>"; echo "<td>"."<a href='delete.php?id=$row[id]'>"."Delete"."</a>"."</td>"; echo "</tr>"; ++$n; } mysql_close($db); ?> </table></form></body></html>
第24行的那个数组能不能改成动态的,要不然所有按钮都只操作同一条数据,应该怎么改啊?
<html><head><script type="text/javascript" src="/jquery/jquery.js"> </script><script type="text/javascript"> $(document).ready(function(){ $(".btn1").click(function(){ $(".btn1").hide(); $(".btn2").show(); }); $(".btn2").click(function(){ $(".btn1").show(); $(".btn2").hide(); }); }); </script></head><body><button class="btn1" style="display:none">update</button><button class="btn2">save</button></body></html>
刚才描述的不是很清楚 写了个测试的代码 你可以参考
XML/HTML code
?
12345678910111213141516171819202122
100db36a723c770d327fc0aef2ce13b1 93f0f5c25f18dab9d176bd4f6de5d30e 5046bdce3c6c6f0cad63c086163d68ef2cacc6d41bbb37262a98f745aa00fbf0 5cd6e472395e766622bc5d31b556eb7a $(document).ready(function……
谢谢你,我没学过ajax和jq。
items = tds.join(',');
好固执的孩纸啊
function change(obj) { //可以传递个当前对象过来 var tds = document.getElementsByTagName("td"); var t1 = document.getElementById("a").innerHTML; var txt = document.createElement("input"); txt.type = "text"; txt.value = t1; txt.id = "sort_t"; obj.parentNode.childNodes[1].appendChild(txt); //添加至第二个td,可根据需要修改 txt.select(); }
调用时,
change(this)
还有你的id命名重复了,这样只能获取第一个

長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的增長


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

禪工作室 13.0.1
強大的PHP整合開發環境

記事本++7.3.1
好用且免費的程式碼編輯器

SecLists
SecLists是最終安全測試人員的伙伴。它是一個包含各種類型清單的集合,這些清單在安全評估過程中經常使用,而且都在一個地方。 SecLists透過方便地提供安全測試人員可能需要的所有列表,幫助提高安全測試的效率和生產力。清單類型包括使用者名稱、密碼、URL、模糊測試有效載荷、敏感資料模式、Web shell等等。測試人員只需將此儲存庫拉到新的測試機上,他就可以存取所需的每種類型的清單。

ZendStudio 13.5.1 Mac
強大的PHP整合開發環境

EditPlus 中文破解版
體積小,語法高亮,不支援程式碼提示功能