ホームページ  >  記事  >  バックエンド開発  >  ボタン列を検出

ボタン列を検出

WBOY
WBOYオリジナル
2016-06-23 14:03:22976ブラウズ

ボタンをクリックして変更 (この) イベントをトリガーし、ボタンが配置されている行の ID を取得してから、changeTotext() メソッドを呼び出して必要なセルをテキスト ボックスに変換してデータを変更したい、関数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='width:80px;height=60px'/>" . "</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>


ディスカッション (解決策) に返信

セルのコンテンツを div に配置し、div の contenteditable 属性を動的に設定して変更します
contentEditable

声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。