检测按钮所在行

php中文网
发布: 2016-06-23 14:03:22
原创
1159人浏览过

我想通过点击button触发change(this)事件,获取按钮所在行的id,然后调用changeTotext()方法,使所需要的单元格变换成文本框来进行修改数据,function change(obj){}方法不会写。

<!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 changeTotext()           {                var tdValue = obj.innerText;               obj.innerText = "";               var txt = document.createElement("input");               txt.type = "text";               txt.value = tdValue;               txt.id = "_text_000000000_";               txt.setAttribute("className","text");               obj.appendChild(txt);               txt.select();            }           function change(obj){			        	              }        	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 id='a'>" . $row['id'] . "</td>";	  echo "<td id='b'>" . $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="max-width:90%"/ alt="检测按钮所在行" >" . "</td>";	  echo "<td id='bg$n'>".     		"<input id='btnshow$n' type='button' value='Update' onclick='showtd($n);change(this)' />".     		"</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>
登录后复制

行者AI
行者AI

行者AI绘图创作,唤醒新的灵感,创造更多可能

行者AI 100
查看详情 行者AI

回复讨论(解决方案)

把单元格的内容放在 div 中,动态设置 div 的 contenteditable 属性就可实现修改
contentEditable

最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号