求助如何点击按钮更新数据?
我希望点击“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

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

The Storage::download method of the Laravel framework provides a concise API for safely handling file downloads while managing abstractions of file storage. Here is an example of using Storage::download() in the example controller:

PHP logging is essential for monitoring and debugging web applications, as well as capturing critical events, errors, and runtime behavior. It provides valuable insights into system performance, helps identify issues, and supports faster troubleshoot

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

Laravel's service container and service providers are fundamental to its architecture. This article explores service containers, details service provider creation, registration, and demonstrates practical usage with examples. We'll begin with an ove
